@@ -1306,33 +1306,40 @@ def assert_frame_equal(left, right, check_dtype=True,
1306
1306
check_categorical = True ,
1307
1307
check_like = False ,
1308
1308
obj = 'DataFrame' ):
1309
- """Check that left and right DataFrame are equal.
1309
+ """
1310
+ Check that left and right DataFrame are equal.
1311
+
1312
+ This function is intended to compare two DataFrames and output any
1313
+ differences. Is is mostly intended for use in unit tests.
1314
+ Additional parameters allow varying the strictness of the
1315
+ equality checks performed.
1310
1316
1311
1317
Parameters
1312
1318
----------
1313
1319
left : DataFrame
1320
+ First DataFrame to compare.
1314
1321
right : DataFrame
1322
+ Second DataFrame to compare.
1315
1323
check_dtype : bool, default True
1316
1324
Whether to check the DataFrame dtype is identical.
1317
- check_index_type : bool / string {'equiv'}, default False
1325
+ check_index_type : {'equiv'} or bool , default 'equiv'
1318
1326
Whether to check the Index class, dtype and inferred_type
1319
1327
are identical.
1320
- check_column_type : bool / string {'equiv'}, default False
1328
+ check_column_type : {'equiv'} or bool , default 'equiv'
1321
1329
Whether to check the columns class, dtype and inferred_type
1322
1330
are identical.
1323
- check_frame_type : bool, default False
1331
+ check_frame_type : bool, default True
1324
1332
Whether to check the DataFrame class is identical.
1325
1333
check_less_precise : bool or int, default False
1326
1334
Specify comparison precision. Only used when check_exact is False.
1327
1335
5 digits (False) or 3 digits (True) after decimal points are compared.
1328
- If int, then specify the digits to compare
1336
+ If int, then specify the digits to compare.
1329
1337
check_names : bool, default True
1330
1338
Whether to check that the `names` attribute for both the `index`
1331
1339
and `column` attributes of the DataFrame is identical, i.e.
1332
1340
1333
1341
* left.index.names == right.index.names
1334
1342
* left.columns.names == right.columns.names
1335
-
1336
1343
by_blocks : bool, default False
1337
1344
Specify how to compare internal data. If False, compare by columns.
1338
1345
If True, compare by blocks.
@@ -1345,10 +1352,39 @@ def assert_frame_equal(left, right, check_dtype=True,
1345
1352
check_like : bool, default False
1346
1353
If True, ignore the order of index & columns.
1347
1354
Note: index labels must match their respective rows
1348
- (same as in columns) - same labels must be with the same data
1355
+ (same as in columns) - same labels must be with the same data.
1349
1356
obj : str, default 'DataFrame'
1350
1357
Specify object name being compared, internally used to show appropriate
1351
- assertion message
1358
+ assertion message.
1359
+
1360
+ See Also
1361
+ --------
1362
+ assert_series_equal : Equivalent method for asserting Series equality.
1363
+ DataFrame.equals : Check DataFrame equality.
1364
+
1365
+ Examples
1366
+ --------
1367
+ This example shows comparing two DataFrames that are equal
1368
+ but with columns of differing dtypes.
1369
+
1370
+ >>> from pandas.util.testing import assert_frame_equal
1371
+ >>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
1372
+ >>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]})
1373
+
1374
+ df1 equals itself.
1375
+ >>> assert_frame_equal(df1, df1)
1376
+
1377
+ df1 differs from df2 as column 'b' is of a different type.
1378
+ >>> assert_frame_equal(df1, df2)
1379
+ Traceback (most recent call last):
1380
+ AssertionError: Attributes are different
1381
+
1382
+ Attribute "dtype" are different
1383
+ [left]: int64
1384
+ [right]: float64
1385
+
1386
+ Ignore differing dtypes in columns with check_dtype.
1387
+ >>> assert_frame_equal(df1, df2, check_dtype=False)
1352
1388
"""
1353
1389
1354
1390
# instance validation
0 commit comments