From b8a7530262013a48fa8640761424857a04fdce0e Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Fri, 31 Aug 2018 14:34:11 +0100 Subject: [PATCH 1/7] Correct assert_frame_equal doc string Correct default values in assert_frame_equal --- pandas/util/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 1eedb9e2a8274..779469cd4505d 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1314,10 +1314,10 @@ def assert_frame_equal(left, right, check_dtype=True, right : DataFrame check_dtype : bool, default True Whether to check the DataFrame dtype is identical. - check_index_type : bool / string {'equiv'}, default False + check_index_type : bool / string {'equiv'}, default 'equiv' Whether to check the Index class, dtype and inferred_type are identical. - check_column_type : bool / string {'equiv'}, default False + check_column_type : bool / string {'equiv'}, default 'equiv' Whether to check the columns class, dtype and inferred_type are identical. check_frame_type : bool, default False From 234cb53765551fa449499d01ce025c957216b6c9 Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Fri, 31 Aug 2018 14:44:30 +0100 Subject: [PATCH 2/7] DOC: correct assert_frame_equal docstring --- pandas/util/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 779469cd4505d..44d287db014c7 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1320,7 +1320,7 @@ def assert_frame_equal(left, right, check_dtype=True, check_column_type : bool / string {'equiv'}, default 'equiv' Whether to check the columns class, dtype and inferred_type are identical. - check_frame_type : bool, default False + check_frame_type : bool, default True Whether to check the DataFrame class is identical. check_less_precise : bool or int, default False Specify comparison precision. Only used when check_exact is False. From 62f29a0b7e38602b79fbe310a9f666b2a0f1a358 Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Fri, 31 Aug 2018 18:11:38 +0100 Subject: [PATCH 3/7] DOC: update assert_frame_equal docstring --- pandas/util/testing.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 44d287db014c7..75df1a5e7d1d2 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1306,12 +1306,15 @@ def assert_frame_equal(left, right, check_dtype=True, check_categorical=True, check_like=False, obj='DataFrame'): - """Check that left and right DataFrame are equal. + """ + Check that left and right DataFrame are equal. Parameters ---------- left : DataFrame + First frame to compare. right : DataFrame + Second frame to compare. check_dtype : bool, default True Whether to check the DataFrame dtype is identical. check_index_type : bool / string {'equiv'}, default 'equiv' @@ -1325,14 +1328,14 @@ def assert_frame_equal(left, right, check_dtype=True, check_less_precise : bool or int, default False Specify comparison precision. Only used when check_exact is False. 5 digits (False) or 3 digits (True) after decimal points are compared. - If int, then specify the digits to compare + If int, then specify the digits to compare. check_names : bool, default True Whether to check that the `names` attribute for both the `index` and `column` attributes of the DataFrame is identical, i.e. * left.index.names == right.index.names * left.columns.names == right.columns.names - + . by_blocks : bool, default False Specify how to compare internal data. If False, compare by columns. If True, compare by blocks. @@ -1345,10 +1348,10 @@ def assert_frame_equal(left, right, check_dtype=True, check_like : bool, default False If True, ignore the order of index & columns. Note: index labels must match their respective rows - (same as in columns) - same labels must be with the same data + (same as in columns) - same labels must be with the same data. obj : str, default 'DataFrame' Specify object name being compared, internally used to show appropriate - assertion message + assertion message. """ # instance validation From 0f8cb0810be6d53df0714e7137194744989e0c98 Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Sun, 2 Sep 2018 10:59:57 +0100 Subject: [PATCH 4/7] DOC: update assert_frame_equal docstring updates --- pandas/util/testing.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 75df1a5e7d1d2..46386baa172f8 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1335,7 +1335,6 @@ def assert_frame_equal(left, right, check_dtype=True, * left.index.names == right.index.names * left.columns.names == right.columns.names - . by_blocks : bool, default False Specify how to compare internal data. If False, compare by columns. If True, compare by blocks. @@ -1352,6 +1351,11 @@ def assert_frame_equal(left, right, check_dtype=True, obj : str, default 'DataFrame' Specify object name being compared, internally used to show appropriate assertion message. + + See Also + -------- + assert_series_equal: equivalent method to this for asserting Series equality + DataFrame.equals: check DataFrame equality """ # instance validation From 00198554d9688743e1b9645d17946003cd5e08ae Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Sun, 2 Sep 2018 11:06:04 +0100 Subject: [PATCH 5/7] DOC: update assert_frame_equal, fix line length --- pandas/util/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 46386baa172f8..e280046198a01 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1354,7 +1354,7 @@ def assert_frame_equal(left, right, check_dtype=True, See Also -------- - assert_series_equal: equivalent method to this for asserting Series equality + assert_series_equal: equivalent method for asserting Series equality DataFrame.equals: check DataFrame equality """ From 3c532ce4e82bd375d69e959878a1e4b58563be80 Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Mon, 3 Sep 2018 11:50:06 +0100 Subject: [PATCH 6/7] DOC: update assert_frame_equal equiv formatting --- pandas/util/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index e280046198a01..db04145ccf5c5 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1317,10 +1317,10 @@ def assert_frame_equal(left, right, check_dtype=True, Second frame to compare. check_dtype : bool, default True Whether to check the DataFrame dtype is identical. - check_index_type : bool / string {'equiv'}, default 'equiv' + check_index_type : {'equiv'} or bool, default 'equiv' Whether to check the Index class, dtype and inferred_type are identical. - check_column_type : bool / string {'equiv'}, default 'equiv' + check_column_type : {'equiv'} or bool, default 'equiv' Whether to check the columns class, dtype and inferred_type are identical. check_frame_type : bool, default True From 6a861d79fcc4971cbd84dfad0cd787dc3e30cf9f Mon Sep 17 00:00:00 2001 From: Barry Fitzgerald Date: Mon, 3 Sep 2018 12:52:42 +0100 Subject: [PATCH 7/7] DOC: update assert_frame_equal equiv further updates --- pandas/util/testing.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index db04145ccf5c5..089e35e8e93b2 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1309,12 +1309,17 @@ def assert_frame_equal(left, right, check_dtype=True, """ Check that left and right DataFrame are equal. + This function is intended to compare two DataFrames and output any + differences. Is is mostly intended for use in unit tests. + Additional parameters allow varying the strictness of the + equality checks performed. + Parameters ---------- left : DataFrame - First frame to compare. + First DataFrame to compare. right : DataFrame - Second frame to compare. + Second DataFrame to compare. check_dtype : bool, default True Whether to check the DataFrame dtype is identical. check_index_type : {'equiv'} or bool, default 'equiv' @@ -1354,8 +1359,32 @@ def assert_frame_equal(left, right, check_dtype=True, See Also -------- - assert_series_equal: equivalent method for asserting Series equality - DataFrame.equals: check DataFrame equality + assert_series_equal : Equivalent method for asserting Series equality. + DataFrame.equals : Check DataFrame equality. + + Examples + -------- + This example shows comparing two DataFrames that are equal + but with columns of differing dtypes. + + >>> from pandas.util.testing import assert_frame_equal + >>> df1 = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) + >>> df2 = pd.DataFrame({'a': [1, 2], 'b': [3.0, 4.0]}) + + df1 equals itself. + >>> assert_frame_equal(df1, df1) + + df1 differs from df2 as column 'b' is of a different type. + >>> assert_frame_equal(df1, df2) + Traceback (most recent call last): + AssertionError: Attributes are different + + Attribute "dtype" are different + [left]: int64 + [right]: float64 + + Ignore differing dtypes in columns with check_dtype. + >>> assert_frame_equal(df1, df2, check_dtype=False) """ # instance validation