Skip to content

Commit b552dc9

Browse files
authored
DEPR: mismatched null-likes in tm.assert_foo_equal (#58023)
1 parent 5703f11 commit b552dc9

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

Diff for: doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Removal of prior version deprecations/changes
211211
- All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`)
212212
- All arguments in :meth:`Series.to_dict` are now keyword only (:issue:`56493`)
213213
- Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`)
214+
- 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`)
214215
- Enforced deprecation disallowing parsing datetimes with mixed time zones unless user passes ``utc=True`` to :func:`to_datetime` (:issue:`57275`)
215216
- 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`)
216217
- 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`)

Diff for: pandas/_libs/testing.pyx

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import cmath
22
import math
3-
import warnings
43

54
import numpy as np
65

@@ -18,7 +17,6 @@ from pandas._libs.util cimport (
1817
is_real_number_object,
1918
)
2019

21-
from pandas.util._exceptions import find_stack_level
2220

2321
from pandas.core.dtypes.missing import array_equivalent
2422

@@ -188,15 +186,7 @@ cpdef assert_almost_equal(a, b,
188186
return True
189187
elif checknull(b):
190188
# GH#18463
191-
warnings.warn(
192-
f"Mismatched null-like values {a} and {b} found. In a future "
193-
"version, pandas equality-testing functions "
194-
"(e.g. assert_frame_equal) will consider these not-matching "
195-
"and raise.",
196-
FutureWarning,
197-
stacklevel=find_stack_level(),
198-
)
199-
return True
189+
raise AssertionError(f"Mismatched null-like values {a} != {b}")
200190
raise AssertionError(f"{a} != {b}")
201191
elif checknull(b):
202192
raise AssertionError(f"{a} != {b}")

Diff for: pandas/tests/util/test_assert_almost_equal.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def test_assert_almost_equal_inf(a, b):
311311

312312
@pytest.mark.parametrize("left", objs)
313313
@pytest.mark.parametrize("right", objs)
314-
def test_mismatched_na_assert_almost_equal_deprecation(left, right):
314+
def test_mismatched_na_assert_almost_equal(left, right):
315315
left_arr = np.array([left], dtype=object)
316316
right_arr = np.array([right], dtype=object)
317317

@@ -331,19 +331,19 @@ def test_mismatched_na_assert_almost_equal_deprecation(left, right):
331331
)
332332

333333
else:
334-
with tm.assert_produces_warning(FutureWarning, match=msg):
334+
with pytest.raises(AssertionError, match=msg):
335335
_assert_almost_equal_both(left, right, check_dtype=False)
336336

337337
# TODO: to get the same deprecation in assert_numpy_array_equal we need
338338
# to change/deprecate the default for strict_nan to become True
339339
# TODO: to get the same deprecation in assert_index_equal we need to
340340
# change/deprecate array_equivalent_object to be stricter, as
341341
# assert_index_equal uses Index.equal which uses array_equivalent.
342-
with tm.assert_produces_warning(FutureWarning, match=msg):
342+
with pytest.raises(AssertionError, match="Series are different"):
343343
tm.assert_series_equal(
344344
Series(left_arr, dtype=object), Series(right_arr, dtype=object)
345345
)
346-
with tm.assert_produces_warning(FutureWarning, match=msg):
346+
with pytest.raises(AssertionError, match="DataFrame.iloc.* are different"):
347347
tm.assert_frame_equal(
348348
DataFrame(left_arr, dtype=object), DataFrame(right_arr, dtype=object)
349349
)

0 commit comments

Comments
 (0)