Skip to content

Commit db97089

Browse files
pablojimWillAyd
authored andcommitted
Correct assert_frame_equal doc string (#22552)
1 parent 100906e commit db97089

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

pandas/util/testing.py

+44-8
Original file line numberDiff line numberDiff line change
@@ -1306,33 +1306,40 @@ def assert_frame_equal(left, right, check_dtype=True,
13061306
check_categorical=True,
13071307
check_like=False,
13081308
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.
13101316
13111317
Parameters
13121318
----------
13131319
left : DataFrame
1320+
First DataFrame to compare.
13141321
right : DataFrame
1322+
Second DataFrame to compare.
13151323
check_dtype : bool, default True
13161324
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'
13181326
Whether to check the Index class, dtype and inferred_type
13191327
are identical.
1320-
check_column_type : bool / string {'equiv'}, default False
1328+
check_column_type : {'equiv'} or bool, default 'equiv'
13211329
Whether to check the columns class, dtype and inferred_type
13221330
are identical.
1323-
check_frame_type : bool, default False
1331+
check_frame_type : bool, default True
13241332
Whether to check the DataFrame class is identical.
13251333
check_less_precise : bool or int, default False
13261334
Specify comparison precision. Only used when check_exact is False.
13271335
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.
13291337
check_names : bool, default True
13301338
Whether to check that the `names` attribute for both the `index`
13311339
and `column` attributes of the DataFrame is identical, i.e.
13321340
13331341
* left.index.names == right.index.names
13341342
* left.columns.names == right.columns.names
1335-
13361343
by_blocks : bool, default False
13371344
Specify how to compare internal data. If False, compare by columns.
13381345
If True, compare by blocks.
@@ -1345,10 +1352,39 @@ def assert_frame_equal(left, right, check_dtype=True,
13451352
check_like : bool, default False
13461353
If True, ignore the order of index & columns.
13471354
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.
13491356
obj : str, default 'DataFrame'
13501357
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)
13521388
"""
13531389

13541390
# instance validation

0 commit comments

Comments
 (0)