diff --git a/pandas/_testing.py b/pandas/_testing.py index 6424a8097fbf1..0180169973e0c 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -1104,6 +1104,7 @@ def assert_series_equal( check_datetimelike_compat=False, check_categorical=True, check_category_order=True, + check_freq=True, obj="Series", ): """ @@ -1142,6 +1143,10 @@ def assert_series_equal( Whether to compare category order of internal Categoricals. .. versionadded:: 1.0.2 + check_freq : bool, default True + Whether to check the `freq` attribute on a DatetimeIndex or TimedeltaIndex. + + .. versionadded:: 1.1.0 obj : str, default 'Series' Specify object name being compared, internally used to show appropriate assertion message. @@ -1171,7 +1176,7 @@ def assert_series_equal( check_categorical=check_categorical, obj=f"{obj}.index", ) - if isinstance(left.index, (pd.DatetimeIndex, pd.TimedeltaIndex)): + if check_freq and isinstance(left.index, (pd.DatetimeIndex, pd.TimedeltaIndex)): lidx = left.index ridx = right.index assert lidx.freq == ridx.freq, (lidx.freq, ridx.freq) @@ -1274,6 +1279,7 @@ def assert_frame_equal( check_datetimelike_compat=False, check_categorical=True, check_like=False, + check_freq=True, obj="DataFrame", ): """ @@ -1327,6 +1333,10 @@ def assert_frame_equal( 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. + check_freq : bool, default True + Whether to check the `freq` attribute on a DatetimeIndex or TimedeltaIndex. + + .. versionadded:: 1.1.0 obj : str, default 'DataFrame' Specify object name being compared, internally used to show appropriate assertion message. @@ -1433,6 +1443,7 @@ def assert_frame_equal( check_names=check_names, check_datetimelike_compat=check_datetimelike_compat, check_categorical=check_categorical, + check_freq=check_freq, obj=f'{obj}.iloc[:, {i}] (column name="{col}")', ) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 299ae2f41d676..c937f9ac42818 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -1552,12 +1552,16 @@ def check_col(key, name, size): & (df_new.A > 0) & (df_new.B < 0) ] - tm.assert_frame_equal(result, expected, check_index_type=False) + tm.assert_frame_equal( + result, expected, check_index_type=False, check_freq=False + ) # yield an empty frame result = store.select("df", "string='foo' and string2='cool'") expected = df_new[(df_new.string == "foo") & (df_new.string2 == "cool")] - tm.assert_frame_equal(result, expected, check_index_type=False) + tm.assert_frame_equal( + result, expected, check_index_type=False, check_freq=False + ) with ensure_clean_store(setup_path) as store: # doc example @@ -1577,11 +1581,16 @@ def check_col(key, name, size): result = store.select("df_dc", "B>0") expected = df_dc[df_dc.B > 0] - tm.assert_frame_equal(result, expected, check_index_type=False) + tm.assert_frame_equal( + result, expected, check_index_type=False, check_freq=False + ) result = store.select("df_dc", ["B > 0", "C > 0", "string == foo"]) expected = df_dc[(df_dc.B > 0) & (df_dc.C > 0) & (df_dc.string == "foo")] - tm.assert_frame_equal(result, expected, check_index_type=False) + tm.assert_frame_equal( + result, expected, check_index_type=False, check_freq=False + ) + # FIXME: 2020-05-07 freq check randomly fails in the CI with ensure_clean_store(setup_path) as store: # doc example part 2