Repository navigation
Fix some pandas nightly deprecation warnings - #12341
Conversation
Unit Test ResultsSee 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 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.♻️ This comment has been updated with latest results. |
|
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. |
|
updated. test_datetime.py now uses |
|
Could you also fix the linting failures? |
|
Lint fixed in 5048e8c — |
- 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
5048e8c to
0a875ef
Compare
- 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.
|
Pushed cbd95f0.
Verified locally on pandas 2.3.3: |
…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.
|
I was wrong with my previous attempt, so going on another round. diving deeper in,
The warning fired from a nested call inside pandas's own New approach in latest commit:
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 so net: -4 failures with one likely flake regression ( |
crusaderky
left a comment
There was a problem hiding this comment.
I hammered the PR a bit. It's now ready for merging. Thank you!
Summary
Fixes the trivial subset of pandas nightly deprecation failures from #12337. The changes address deprecated datetime accessor names, the
exactparameter default change, andDataFrame.from_dictwith list arguments.Changes
Datetime accessor deprecations (
test_datetime.py,_collection.py):dayofweek,dayofyear,daysinmonth) from the test parametrize list sinceday_of_week,day_of_year,days_in_monthare already testedday_of_weekandday_of_yeartoDatetimeIndex._dt_attributesso the new names work on dask DatetimeIndex objectsexactparameter warning (utils.py):assert_frame_equalandassert_series_equalcalls inassert_eqwith a warning filter for theexact='equiv'deprecation. The warning comes from pandas' internalassert_index_equalcall (not ours), so filtering is the right fix here.from_dictdeprecation (test_json.py):pd.DataFrame.from_dict(json.load(...))withpd.DataFrame(json.load(...))intest_read_json_fkeyword, since passing a list tofrom_dictis deprecated.Not included (per @crusaderky's comment flagging these as potentially non-trivial):
test_cumulative_empty_partitionsfailuresTesting
These are test-only changes (the
_dt_attributesupdate is the only production code change, adding new attribute names). CI will validate.Fixes #12337
This contribution was developed with AI assistance (Claude Code).