Skip to content

TST: assert_frame_equal now raises for mismatching freq in MultiIndex level #66761

Description

@jorisvandenbossche

We already raised for a mismatching freq for a normal Datetime/TimedeltaIndex in assert_frame_equal, and #65194 updated assert_index_equal to have a similar behaviour (behind a deprecation warning first).

But a potential side effect of that PR (didn't verify) is that this now raises for a MultiIndex level:

dates = pd.date_range("2012-01-01", periods=3)
midx1 = pd.MultiIndex.from_arrays([dates, [1, 2, 3]])
midx2 = pd.MultiIndex.from_arrays([dates._with_freq(None), [1, 2, 3]])
df1 = pd.DataFrame({"a": [1, 2, 3]}, index=midx1)
df2 = pd.DataFrame({"a": [1, 2, 3]}, index=midx2)

On main:

# this now raises a warning -> expected
>>> pd.testing.assert_index_equal(midx1, midx2)
Pandas4Warning: assert_index_equal will check the 'freq' attribute by default in a future version; these freqs <Day> and None do not match. Pass check_freq=True or check_freq=False to silence this warning

# this directly errors
>>> pd.testing.assert_frame_equal(df1, df2)
...
Attribute "freq" are different
[left]:  <Day>
[right]: None

while with released pandas (3.0.5) both cases pass:

>>> pd.testing.assert_index_equal(midx1, midx2)
>>> pd.testing.assert_frame_equal(df1, df2)

cc @jbrockmendel

Metadata

Metadata

Assignees

Labels

Testingpandas testing functions or related to the test suite

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions