Skip to content

Escalate .apply deprecation to FutureWarning (GH11721) - #11784

Open
Anju522 wants to merge 6 commits into
pydata:mainfrom
Anju522:apply-futurewarning
Open

Anju522 wants to merge 6 commits into
pydata:mainfrom
Anju522:apply-futurewarning

Conversation

@Anju522

@Anju522 Anju522 commented Oct 22, 2026 •

Copy link
Copy Markdown

Description

PendingDeprecationWarning is hidden by default, so users calling .apply never saw it.

Changed the PendingDeprecationWarning of Dataset.apply, both GroupBy.apply methods (DataArray and Dataset) and both Resample.apply methods to a FutureWarning, so that users can now see the warning.

Tests were already there for checking PendingDeprecationWarning of Dataset.apply, changed that to check for FutureWarning. Added similar tests for GroupBy.apply and Resample.apply ( they check for the warning and whether the result of apply is same as map).
Added this set of changes to the whats-new.rst under v2026.09.1's Deprecations section.

Checklist

Dataset.apply, GroupBy.apply and Resample.apply have emitted a
PendingDeprecationWarning, change that to FutureWarning instead.
Add tests to check this warning for GroupBy.apply and Resample.apply.

@headtr1ck headtr1ck 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.

LGTM, thanks

@headtr1ck

Copy link
Copy Markdown
Collaborator

Could you use emit_user_level_warning from xarray.core.utils for these? It finds the first stack frame outside xarray, so the warning points at the user's code even if .apply is reached through another xarray call, and it's what the other #11721 PRs use:

emit_user_level_warning(
    "Dataset.apply is deprecated, use Dataset.map instead.",
    FutureWarning,
)

@Anju522

Anju522 commented Oct 22, 2026

Copy link
Copy Markdown
Author

Got it, I saw that there were only two warnings.warn usage on xarray/core/resample.py , so after replacing it, I removed the import as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants