Skip to content
13 changes: 12 additions & 1 deletion pandas/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ def assert_series_equal(
check_datetimelike_compat=False,
check_categorical=True,
check_category_order=True,
check_freq=True,
obj="Series",
):
"""
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to below versionadded:: 1.0.2 for check_category_order and add versionadded:: 1.1.0

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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1274,6 +1279,7 @@ def assert_frame_equal(
check_datetimelike_compat=False,
check_categorical=True,
check_like=False,
check_freq=True,
obj="DataFrame",
):
"""
Expand Down Expand Up @@ -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.
Comment on lines +1336 to +1337
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add versionadded:: 1.1.0


.. versionadded:: 1.1.0
obj : str, default 'DataFrame'
Specify object name being compared, internally used to show appropriate
assertion message.
Expand Down Expand Up @@ -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}")',
)

Expand Down
17 changes: 13 additions & 4 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down