BUG: testing.assert_series_equal: inferred check_exact should not be passed down to index check · Issue #57067 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

a = pd.Series(np.zeros(6, dtype=int), [0, 0.2, 0.4, 0.6, 0.8, 1]) b = pd.Series(np.zeros(6, dtype=int), np.linspace(0, 1, 6)) # 0.6000000000000001 pd.testing.assert_series_equal(a, b)

Issue Description

In pandas 2.2.0, the above passes if the series' values dtype is float and fails if the series' values dtype is int. In pandas 2.1.4, it passes in both cases.

The difference seems to be caused by a change in the default for the check_exact in assert_series_equal:

Changed in version 2.2.0: Defaults to True for integer dtypes if none of check_exact, rtol and atol are specified.

What I think is happening is that, in pandas 2.1.4, assert_series_equal was passing down its own default check_exact=False to assert_index_equal - even if the default for the latter is check_exact=True. In 2.2.0, assert_series_equal infers check_exact=True from the values dtype, and then passes it down to assert_index_equal.

Expected Behavior

In my opinion both pandas 2.2.0 and 2.1.4 are wrong here. If the user doesn't explicitly state check_exact, it should default to two potentially different values for the values and the index, which means False for float values, True for int values, and True for the index regardless of dtype (as it already is for assert_index_equal).

Installed Versions

commit : f538741python : 3.12.1.final.0 python-bits : 64 OS : Linux OS-release : 6.5.0-14-generic Version : #14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8

pandas : 2.2.0
numpy : 1.26.3