Skip to content

Fix some pandas nightly deprecation warnings - #12341

Merged
crusaderky merged 7 commits into
dask:mainfrom
tmchow:osc/12337-pandas-deprecations
May 5, 2026
Merged

crusaderky merged 7 commits into
dask:mainfrom
tmchow:osc/12337-pandas-deprecations

Conversation

@tmchow

@tmchow tmchow commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the trivial subset of pandas nightly deprecation failures from #12337. The changes address deprecated datetime accessor names, the exact parameter default change, and DataFrame.from_dict with list arguments.

Changes

Datetime accessor deprecations (test_datetime.py, _collection.py):

  • Removed deprecated names (dayofweek, dayofyear, daysinmonth) from the test parametrize list since day_of_week, day_of_year, days_in_month are already tested
  • Added day_of_week and day_of_year to DatetimeIndex._dt_attributes so the new names work on dask DatetimeIndex objects

exact parameter warning (utils.py):

  • Wrapped assert_frame_equal and assert_series_equal calls in assert_eq with a warning filter for the exact='equiv' deprecation. The warning comes from pandas' internal assert_index_equal call (not ours), so filtering is the right fix here.

from_dict deprecation (test_json.py):

  • Replaced pd.DataFrame.from_dict(json.load(...)) with pd.DataFrame(json.load(...)) in test_read_json_fkeyword, since passing a list to from_dict is deprecated.

Not included (per @crusaderky's comment flagging these as potentially non-trivial):

  • test_cumulative_empty_partitions failures

Testing

These are test-only changes (the _dt_attributes update is the only production code change, adding new attribute names). CI will validate.

Fixes #12337

This contribution was developed with AI assistance (Claude Code).

@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     20 files  ±0       20 suites  ±0   4h 48m 11s ⏱️ - 6m 25s
 18 293 tests ±0   16 938 ✅ +12   1 272 💤 ±0  83 ❌  - 12 
299 496 runs  ±0  257 201 ✅ +11  42 205 💤 +1  90 ❌  - 12 

For more details on these failures, see this check.

Results for commit 69750d8. ± Comparison against base commit 7c7455a.

This pull request removes 4 and adds 4 tests. Note that renamed tests count towards both.
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties[dayofweek]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties[dayofyear]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties[daysinmonth]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties[weekday]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties_deprecated[dayofweek]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties_deprecated[dayofyear]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties_deprecated[daysinmonth]
dask.dataframe.dask_expr.tests.test_datetime ‑ test_datetime_accessor_properties_deprecated[weekday]

♻️ This comment has been updated with latest results.

Comment thread dask/dataframe/utils.py Resolved
@TomAugspurger

Copy link
Copy Markdown
Member

Thanks @tmchow, can you update this?

And take a look at https://github.com/dask/dask/actions/runs/23896488163/job/69682383916?pr=12341 to see which tests are still failing.

@tmchow

tmchow commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

updated. test_datetime.py now uses pytest.mark.skipif(PANDAS_GE_300) for the deprecated accessors, and utils.py passes check_index_type/check_column_type explicitly on pandas >= 3.0 instead of catching the warning.

Comment thread dask/dataframe/utils.py Resolved
@crusaderky

Copy link
Copy Markdown
Collaborator

Could you also fix the linting failures?

@tmchow

tmchow commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Lint fixed in 5048e8c — ruff check was flagging an unsorted import block in dask/dataframe/utils.py (the dask.dataframe._compat import landed before dask.base/dask.core). Reordered, pre-commit run --all-files is now clean locally.

tmchow added 3 commits April 29, 2026 10:50
- Remove deprecated datetime accessor names (dayofweek, dayofyear,
  daysinmonth) from test parametrize since the new names (day_of_week,
  day_of_year, days_in_month) are already tested
- Add day_of_week and day_of_year to DatetimeIndex._dt_attributes
- Suppress pandas 'equiv' exact parameter deprecation warning in
  assert_eq comparisons
- Replace deprecated pd.DataFrame.from_dict(list) with pd.DataFrame()
  in test_read_json_fkeyword

Fixes #12337 (trivial subset)
Address review feedback from @TomAugspurger:

- test_datetime.py: use conditional skipif(PANDAS_GE_300) for deprecated
  dayofweek/dayofyear/daysinmonth accessors instead of unconditional skip
- utils.py: replace warnings.catch_warnings() with explicit check_index_type
  and check_column_type defaults for pandas >= 3.0
@tmchow
tmchow force-pushed the osc/12337-pandas-deprecations branch from 5048e8c to 0a875ef Compare April 29, 2026 17:50
- Add `weekday` to deprecated datetime accessor names with
  skipif(PANDAS_GE_300), matching dayofweek/dayofyear/daysinmonth.
- Switch check_index_type/check_column_type from "equiv" to True in
  assert_eq for pandas>=3.0. The Pandas4Warning fires on the value
  "equiv" itself, not just the default, so passing it explicitly still
  triggers the deprecation. True is the future pandas 4 default per the
  warning text.
@tmchow

tmchow commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Pushed cbd95f0.

  • Added weekday with skipif(PANDAS_GE_300) alongside the other deprecated accessor names.
  • assert_eq now passes check_index_type=True and check_column_type=True on pandas >= 3.0 instead of "equiv". The Pandas4Warning fires on "equiv" whether it's the default or set explicitly, so setdefault(..., "equiv") still triggered it. True matches the future pandas 4 default per the warning text.

Verified locally on pandas 2.3.3: test_to_dataframe, test_set_index_numeric_columns, and all 26 test_datetime_accessor_properties variants pass. pre-commit run clean. Pandas4Warning isn't reproducible without pandas-nightly so CI will have to confirm.

tmchow added 2 commits April 29, 2026 12:30
…95f0)

cbd95f0 switched from "equiv" to True. That broke ~92 tests in the
pandas-nightly CI run because True requires exact Index class match,
so RangeIndex(start=1, stop=3, step=1) and Index([1, 2], dtype='int64')
no longer compare equal. Pandas itself considers them equivalent under
'equiv', which is what the dask tests rely on.

The Pandas4Warning ("default value of 'equiv' is deprecated") fires
when 'equiv' is the *default*, not when it's set explicitly. Calling
setdefault("check_index_type", "equiv") makes the value explicit and
suppresses the warning for tests that go through assert_eq -- including
the originally cited test_to_dataframe and test_set_index_numeric_columns.

A handful of pre-existing pandas-nightly failures (test_set_index_drop,
test_apply, etc.) hit a code path inside assert_frame_equal where the
warning fires from a nested call that doesn't honor check_index_type.
Those are not addressed by this PR -- they exist on main today.
…ager

The previous attempts (setdefault check_index_type to "equiv" or True) did
not actually suppress the Pandas4Warning that crusaderky cited from
test_to_dataframe and test_set_index_numeric_columns. The warning fires
from a nested call inside pandas's own assert_frame_equal /
assert_series_equal that does not honor the user-facing check_index_type
or check_column_type kwargs, so per-call kwarg overrides cannot reach it.

Add a check_pandas4_equiv_deprecation() context manager in _pandas_compat
mirroring the existing check_groupby_axis_deprecation /
check_observed_deprecation / check_apply_dataframe_deprecation pattern.
Gate it on PANDAS_GE_300 so it is a no-op on older pandas. Wrap the two
relevant tm.assert_*_equal calls in assert_eq.

Drop the previous setdefault block; it was redundant and misleading.
@tmchow

tmchow commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor Author

I was wrong with my previous attempt, so going on another round. diving deeper in, setdefault("check_index_type", "equiv") does not actually suppress the Pandas4Warning. Comparing the pandas-nightly failure lists:

  • main (7c7455a): test_to_dataframe, test_set_index_numeric_columns fail with the warning.
  • cbd95f0 (the True attempt): both still fail.
  • a52103d (revert to setdefault "equiv"): both still fail.

The warning fired from a nested call inside pandas's own assert_frame_equal / assert_series_equal that does not propagate the user-facing check_index_type / check_column_type kwargs, so per-call overrides cannot reach it. This is what tripped me up originally..

New approach in latest commit:

  • add a check_pandas4_equiv_deprecation() context manager in dask/_pandas_compat.py, mirroring the existing check_groupby_axis_deprecation / check_observed_deprecation / check_apply_dataframe_deprecation patterns.
  • it's gated on PANDAS_GE_300, filters only the specific message ("The default value of 'equiv'"), wrapped around the two tm.assert_*_equal calls in assert_eq. Drops the setdefault block (it was redundant and misleading).

This does take the form @TomAugspurger wanted to avoid earlier in this PR (suppressing a warning rather than doing the right thing per pandas version). but after digging thorugh this, i'd argue it now matches the established _pandas_compat.py convention. that said, I'm happy to take a different direction if you'd prefer the kwarg-only approach be retired and the two tests be left as-is for the upstream pandas issue to address. The weekday skipif and the JSON/datetime accessor fixes are unaffected.

so net: -4 failures with one likely flake regression (test_len asserting 100 == 10, looks fixture-pollution-related, untouched by this PR's diff). Will know after pandas-nightly runs on 559668a.

@crusaderky crusaderky changed the title Fix pandas nightly deprecation warnings Fix some pandas nightly deprecation warnings May 5, 2026

@crusaderky crusaderky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hammered the PR a bit. It's now ready for merging. Thank you!

@crusaderky
crusaderky merged commit 5fd159b into dask:main May 5, 2026
18 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pandas nightly is broken

3 participants