Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ Other
- 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`)
- Bug in printing a :class:`DataFrame` with a :class:`DataFrame` stored in :attr:`DataFrame.attrs` raised a ``ValueError`` (:issue:`60455`)
- Bug in printing a :class:`Series` with a :class:`DataFrame` stored in :attr:`Series.attrs` raised a ``ValueError`` (:issue:`60568`)
- Deprecated the keyword ``check_datetimelike_compat`` in :meth:`testing.assert_frame_equal` and :meth:`testing.assert_series_equal` (:issue:`55638`)
- Fixed bug where the :class:`DataFrame` constructor misclassified array-like objects with a ``.name`` attribute as :class:`Series` or :class:`Index` (:issue:`61443`)
- Fixed regression in :meth:`DataFrame.from_records` not initializing subclasses properly (:issue:`57008`)

Expand Down
49 changes: 33 additions & 16 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
NoReturn,
cast,
)
import warnings

import numpy as np

Expand All @@ -15,6 +16,8 @@
from pandas._libs.sparse import SparseIndex
import pandas._libs.testing as _testing
from pandas._libs.tslibs.np_datetime import compare_mismatched_resolutions
from pandas.errors import Pandas4Warning
from pandas.util._decorators import deprecate_kwarg

from pandas.core.dtypes.common import (
is_bool,
Expand Down Expand Up @@ -843,6 +846,7 @@ def assert_extension_array_equal(


# This could be refactored to use the NDFrame.equals method
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
def assert_series_equal(
left,
right,
Expand Down Expand Up @@ -897,6 +901,9 @@ def assert_series_equal(

check_datetimelike_compat : bool, default False
Compare datetime-like which is comparable ignoring dtype.

.. deprecated:: 3.0

check_categorical : bool, default True
Whether to compare internal Categorical exactly.
check_category_order : bool, default True
Expand Down Expand Up @@ -1132,6 +1139,7 @@ def assert_series_equal(


# This could be refactored to use the NDFrame.equals method
@deprecate_kwarg(Pandas4Warning, "check_datetimelike_compat", new_arg_name=None)
def assert_frame_equal(
left,
right,
Expand Down Expand Up @@ -1194,6 +1202,9 @@ def assert_frame_equal(
``check_exact``, ``rtol`` and ``atol`` are specified.
check_datetimelike_compat : bool, default False
Compare datetime-like which is comparable ignoring dtype.

.. deprecated:: 3.0

check_categorical : bool, default True
Whether to compare internal Categorical exactly.
check_like : bool, default False
Expand Down Expand Up @@ -1320,22 +1331,28 @@ def assert_frame_equal(
# use check_index=False, because we do not want to run
# assert_index_equal for each column,
# as we already checked it for the whole dataframe before.
assert_series_equal(
lcol,
rcol,
check_dtype=check_dtype,
check_index_type=check_index_type,
check_exact=check_exact,
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}")',
rtol=rtol,
atol=atol,
check_index=False,
check_flags=False,
)
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message="the 'check_datetimelike_compat' keyword",
category=Pandas4Warning,
)
assert_series_equal(
lcol,
rcol,
check_dtype=check_dtype,
check_index_type=check_index_type,
check_exact=check_exact,
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}")',
rtol=rtol,
atol=atol,
check_index=False,
check_flags=False,
)


def assert_equal(left, right, **kwargs) -> None:
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/util/test_assert_frame_equal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from pandas.errors import Pandas4Warning

import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
Expand Down Expand Up @@ -395,3 +397,19 @@ def test_assert_frame_equal_set_mismatch():
msg = r'DataFrame.iloc\[:, 0\] \(column name="set_column"\) values are different'
with pytest.raises(AssertionError, match=msg):
tm.assert_frame_equal(df1, df2)


def test_datetimelike_compat_deprecated():
# GH#55638
df = DataFrame({"a": [1]})

msg = "the 'check_datetimelike_compat' keyword is deprecated"
with tm.assert_produces_warning(Pandas4Warning, match=msg):
tm.assert_frame_equal(df, df, check_datetimelike_compat=True)
with tm.assert_produces_warning(Pandas4Warning, match=msg):
tm.assert_frame_equal(df, df, check_datetimelike_compat=False)

with tm.assert_produces_warning(Pandas4Warning, match=msg):
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=True)
with tm.assert_produces_warning(Pandas4Warning, match=msg):
tm.assert_series_equal(df["a"], df["a"], check_datetimelike_compat=False)
Loading