Skip to content

DEPR: mismatched null-likes in tm.assert_foo_equal #58023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024
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 @@ -211,6 +211,7 @@ Removal of prior version deprecations/changes
- All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`)
- All arguments in :meth:`Series.to_dict` are now keyword only (:issue:`56493`)
- Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`)
- Enforce deprecation in :func:`testing.assert_series_equal` and :func:`testing.assert_frame_equal` with object dtype and mismatched null-like values, which are now considered not-equal (:issue:`18463`)
- Enforced deprecation disallowing parsing datetimes with mixed time zones unless user passes ``utc=True`` to :func:`to_datetime` (:issue:`57275`)
- Enforced deprecation in :meth:`Series.value_counts` and :meth:`Index.value_counts` with object dtype performing dtype inference on the ``.index`` of the result (:issue:`56161`)
- Enforced deprecation of :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` allowing the ``name`` argument to be a non-tuple when grouping by a list of length 1 (:issue:`54155`)
Expand Down
12 changes: 1 addition & 11 deletions pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import cmath
import math
import warnings

import numpy as np

Expand All @@ -18,7 +17,6 @@ from pandas._libs.util cimport (
is_real_number_object,
)

from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.missing import array_equivalent

Expand Down Expand Up @@ -188,15 +186,7 @@ cpdef assert_almost_equal(a, b,
return True
elif checknull(b):
# GH#18463
warnings.warn(
f"Mismatched null-like values {a} and {b} found. In a future "
"version, pandas equality-testing functions "
"(e.g. assert_frame_equal) will consider these not-matching "
"and raise.",
FutureWarning,
stacklevel=find_stack_level(),
)
return True
raise AssertionError(f"Mismatched null-like values {a} != {b}")
raise AssertionError(f"{a} != {b}")
elif checknull(b):
raise AssertionError(f"{a} != {b}")
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/util/test_assert_almost_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def test_assert_almost_equal_inf(a, b):

@pytest.mark.parametrize("left", objs)
@pytest.mark.parametrize("right", objs)
def test_mismatched_na_assert_almost_equal_deprecation(left, right):
def test_mismatched_na_assert_almost_equal(left, right):
left_arr = np.array([left], dtype=object)
right_arr = np.array([right], dtype=object)

Expand All @@ -331,19 +331,19 @@ def test_mismatched_na_assert_almost_equal_deprecation(left, right):
)

else:
with tm.assert_produces_warning(FutureWarning, match=msg):
with pytest.raises(AssertionError, match=msg):
_assert_almost_equal_both(left, right, check_dtype=False)

# TODO: to get the same deprecation in assert_numpy_array_equal we need
# to change/deprecate the default for strict_nan to become True
# TODO: to get the same deprecation in assert_index_equal we need to
# change/deprecate array_equivalent_object to be stricter, as
# assert_index_equal uses Index.equal which uses array_equivalent.
with tm.assert_produces_warning(FutureWarning, match=msg):
with pytest.raises(AssertionError, match="Series are different"):
tm.assert_series_equal(
Series(left_arr, dtype=object), Series(right_arr, dtype=object)
)
with tm.assert_produces_warning(FutureWarning, match=msg):
with pytest.raises(AssertionError, match="DataFrame.iloc.* are different"):
tm.assert_frame_equal(
DataFrame(left_arr, dtype=object), DataFrame(right_arr, dtype=object)
)
Expand Down