Skip to content

Commit 734f519

Browse files
authored
DEPR: check_datetimelike_compat in assert_foo_equal (#62299)
1 parent 83c9e4a commit 734f519

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ Other
11531153
- Bug in ``divmod`` and ``rdivmod`` with :class:`DataFrame`, :class:`Series`, and :class:`Index` with ``bool`` dtypes failing to raise, which was inconsistent with ``__floordiv__`` behavior (:issue:`46043`)
11541154
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
11551155
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
1156+
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
11561157
- Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`)
11571158
- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)
11581159
-

pandas/_testing/asserters.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
NoReturn,
88
cast,
99
)
10+
import warnings
1011

1112
import numpy as np
1213

@@ -15,6 +16,8 @@
1516
from pandas._libs.sparse import SparseIndex
1617
import pandas._libs.testing as _testing
1718
from pandas._libs.tslibs.np_datetime import compare_mismatched_resolutions
19+
from pandas.errors import Pandas4Warning
20+
from pandas.util._decorators import deprecate_kwarg
1821

1922
from pandas.core.dtypes.common import (
2023
is_bool,
@@ -843,6 +846,7 @@ def assert_extension_array_equal(
843846

844847

845848
# This could be refactored to use the NDFrame.equals method
849+
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
846850
def assert_series_equal(
847851
left,
848852
right,
@@ -897,6 +901,9 @@ def assert_series_equal(
897901
898902
check_datetimelike_compat : bool, default False
899903
Compare datetime-like which is comparable ignoring dtype.
904+
905+
.. deprecated:: 3.0
906+
900907
check_categorical : bool, default True
901908
Whether to compare internal Categorical exactly.
902909
check_category_order : bool, default True
@@ -1132,6 +1139,7 @@ def assert_series_equal(
11321139

11331140

11341141
# This could be refactored to use the NDFrame.equals method
1142+
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
11351143
def assert_frame_equal(
11361144
left,
11371145
right,
@@ -1194,6 +1202,9 @@ def assert_frame_equal(
11941202
``check_exact``, ``rtol`` and ``atol`` are specified.
11951203
check_datetimelike_compat : bool, default False
11961204
Compare datetime-like which is comparable ignoring dtype.
1205+
1206+
.. deprecated:: 3.0
1207+
11971208
check_categorical : bool, default True
11981209
Whether to compare internal Categorical exactly.
11991210
check_like : bool, default False
@@ -1320,22 +1331,28 @@ def assert_frame_equal(
13201331
# use check_index=False, because we do not want to run
13211332
# assert_index_equal for each column,
13221333
# as we already checked it for the whole dataframe before.
1323-
assert_series_equal(
1324-
lcol,
1325-
rcol,
1326-
check_dtype=check_dtype,
1327-
check_index_type=check_index_type,
1328-
check_exact=check_exact,
1329-
check_names=check_names,
1330-
check_datetimelike_compat=check_datetimelike_compat,
1331-
check_categorical=check_categorical,
1332-
check_freq=check_freq,
1333-
obj=f'{obj}.iloc[:, {i}] (column name="{col}")',
1334-
rtol=rtol,
1335-
atol=atol,
1336-
check_index=False,
1337-
check_flags=False,
1338-
)
1334+
with warnings.catch_warnings():
1335+
warnings.filterwarnings(
1336+
"ignore",
1337+
message="the 'check_datetimelike_compat' keyword",
1338+
category=Pandas4Warning,
1339+
)
1340+
assert_series_equal(
1341+
lcol,
1342+
rcol,
1343+
check_dtype=check_dtype,
1344+
check_index_type=check_index_type,
1345+
check_exact=check_exact,
1346+
check_names=check_names,
1347+
check_datetimelike_compat=check_datetimelike_compat,
1348+
check_categorical=check_categorical,
1349+
check_freq=check_freq,
1350+
obj=f'{obj}.iloc[:, {i}] (column name="{col}")',
1351+
rtol=rtol,
1352+
atol=atol,
1353+
check_index=False,
1354+
check_flags=False,
1355+
)
13391356

13401357

13411358
def assert_equal(left, right, **kwargs) -> None:

pandas/tests/util/test_assert_frame_equal.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from pandas.errors import Pandas4Warning
4+
35
import pandas as pd
46
from pandas import DataFrame
57
import pandas._testing as tm
@@ -395,3 +397,19 @@ def test_assert_frame_equal_set_mismatch():
395397
msg = r'DataFrame.iloc\[:, 0\] \(column name="set_column"\) values are different'
396398
with pytest.raises(AssertionError, match=msg):
397399
tm.assert_frame_equal(df1, df2)
400+
401+
402+
def test_datetimelike_compat_deprecated():
403+
# GH#55638
404+
df = DataFrame({"a": [1]})
405+
406+
msg = "the 'check_datetimelike_compat' keyword is deprecated"
407+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
408+
tm.assert_frame_equal(df, df, check_datetimelike_compat=True)
409+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
410+
tm.assert_frame_equal(df, df, check_datetimelike_compat=False)
411+
412+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
413+
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=True)
414+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
415+
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=False)

0 commit comments

Comments
 (0)