Skip to content

Support additional dtypes in resample - #9413

Merged
dcherian merged 18 commits into
pydata:mainfrom
oliverhiggs:resample-dtypes
Sep 7, 2024
Merged

Support additional dtypes in resample#9413
dcherian merged 18 commits into
pydata:mainfrom
oliverhiggs:resample-dtypes

Conversation

@oliverhiggs

Copy link
Copy Markdown
Contributor

pandas.BaseOffset, pandas.Timedelta, datetime.timedelta, and BaseCFTimeOffset are now all supported datatypes for resampling.

Closes#9408

@welcome

welcomeBot commented Aug 29, 2024

Copy link
Copy Markdown

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

Comment threadxarray/groupers.py Outdated
Comment threadxarray/core/common.py Outdated
@max-sixty

Copy link
Copy Markdown
Collaborator

Looks good! Can we add a test?

pandas.BaseOffset, pandas.Timedelta, datetime.timedelta, and BaseCFTimeOffset are now all supported datatypes for resampling.
Comment threadxarray/groupers.py Outdated
Comment threadxarray/tests/test_groupby.py Outdated
@oliverhiggs

Copy link
Copy Markdown
ContributorAuthor

This is failing a test on the bare-minimum environment because of a FutureWarning caused by pandas 2.0.3 using 'S' instead of 's' for an internal frequency string. I noticed there are other FutureWarnings that occur during the test run but don't cause a test failure, why is this? Is it possible to do the same with my test?

e.g. This warning does not cause a test failure.

 /home/runner/work/xarray/xarray/xarray/tests/test_variable.py:2421: FutureWarning: the `pandas.MultiIndex` object(s) passed as 'x' coordinate(s) or data variable(s) will no longer be implicitly promoted and wrapped into multiple indexed coordinates in the future (i.e., one coordinate for each multi-index level + one dimension coordinate). If you want to keep this behavior, you need to first wrap it explicitly using `mindex_coords = xarray.Coordinates.from_pandas_multiindex(mindex_obj, 'dim')` and pass it as coordinates, e.g., `xarray.Dataset(coords=mindex_coords)`, `dataset.assign_coords(mindex_coords)` or `dataarray.assign_coords(mindex_coords)`.
ds = Dataset(coords={"x": midx})

Comment threaddoc/whats-new.rst Outdated
@dcherian

dcherian commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

yes we can take it from here. Thanks for your contribution and welcome to Xarray!

@dcheriandcherian added the plan to merge Final call for comments label Sep 5, 2024
@oliverhiggs

Copy link
Copy Markdown
ContributorAuthor

Thanks! And thanks for creating such a welcoming atmosphere for new contributors.

@spencerkclarkspencerkclark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@oliverhiggs sorry for the delay—this looks great!

To answer your question about the warning leading to a test failure—a few months ago we made a change to make any new warnings emitted in the test suite errors (#8974). In that PR some code was added to ignore some existing warnings (the MultiIndex warning you noted being one of them).

We've dealt with the frequency string deprecation warning in the past in the context of old pandas versions (#8627); I made a suggestion which I think may resolve it.

Comment threadxarray/coding/cftime_offsets.py Outdated
Comment threadxarray/coding/cftime_offsets.py Outdated
dcherianand others added 2 commits September 7, 2024 07:17
Co-authored-by: Spencer Clark <spencerkclark@gmail.com>
Comment threadxarray/coding/cftime_offsets.py Outdated
@dcherian
dcherian merged commit a74a605 into pydata:mainSep 7, 2024
@welcome

ghost commented Sep 7, 2024

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

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

Labels

plan to mergeFinal call for comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resample no longer works with Pandas DateOffset or Timedelta objects

4 participants

@oliverhiggs@max-sixty@dcherian@spencerkclark