Skip to content

fix mean for datetime-like using the respective time resolution unit - #9977

Merged
kmuehlbauer merged 9 commits into
pydata:mainfrom
kmuehlbauer:fix-datetime-mean
Jan 29, 2025
Merged

fix mean for datetime-like using the respective time resolution unit#9977
kmuehlbauer merged 9 commits into
pydata:mainfrom
kmuehlbauer:fix-datetime-mean

Conversation

@kmuehlbauer

@kmuehlbauerkmuehlbauer commented Jan 23, 2025

Copy link
Copy Markdown
Contributor

@sfinkens

Copy link
Copy Markdown

Works fine, thanks a lot!

@kmuehlbauer

Copy link
Copy Markdown
ContributorAuthor

Works fine, thanks a lot!

Great, let's wait for some more feedback. @dcherian and @spencerkclark would you mind taking a look here?

Comment threadxarray/core/duck_array_ops.py Outdated

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

Thanks @kmuehlbauer for jumping on this—a couple more comments. I think it was useful to revisit this code independent of the non-nanosecond update.

Comment threadxarray/core/duck_array_ops.py Outdated
Comment threadxarray/core/duck_array_ops.py
Comment threadxarray/core/duck_array_ops.py Outdated
Comment threadxarray/core/duck_array_ops.py Outdated
@kmuehlbauer

Copy link
Copy Markdown
ContributorAuthor

Apart from the loss of resolution when the calculated mean contains fractional part (but is in alignment with pandas and numpy), this is working for all available resolutions. In case of ns resolution this replicates the old behaviour.

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

Thanks @kmuehlbauer—this looks good to me now!

Comment threadxarray/core/duck_array_ops.py Outdated
Comment threadxarray/tests/test_duck_array_ops.py Outdated
Comment threadxarray/tests/test_duck_array_ops.py Outdated
Comment threadxarray/core/duck_array_ops.py Outdated
Comment threadxarray/core/duck_array_ops.py Outdated
Co-authored-by: Spencer Clark <spencerkclark@gmail.com>
@kmuehlbauer

Copy link
Copy Markdown
ContributorAuthor

Thanks @kmuehlbauer—this looks good to me now!

Thanks @spencerkclark, good to have a decent solution here for the time being.

@kmuehlbauerkmuehlbauer added the plan to merge Final call for comments label Jan 27, 2025
@kmuehlbauer

kmuehlbauer commented Jan 29, 2025

Copy link
Copy Markdown
ContributorAuthor

Thanks @spencerkclark and @dcherian for review and approval. Thanks @sfinkens for testing. Getting this in now.

@kmuehlbauer
kmuehlbauer merged commit e28f171 into pydata:mainJan 29, 2025
@kmuehlbauer
kmuehlbauer deleted the fix-datetime-mean branch January 29, 2025 08:37
dcherian added a commit that referenced this pull request Jan 30, 2025
* main: (79 commits)
fix mean for datetime-like using the respective time resolution unit (#9977)
Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (#9965)
remove gate and add a test (#9958)
Remove repetitive that (replace it with the) (#9994)
add shxarray to the xarray ecosystem list (#9995)
Add `shards` to `valid_encodings` to enable sharded Zarr writing (#9948)
Use flox for grouped first, last (#9986)
Bump the actions group with 2 updates (#9989)
Fix some typing (#9988)
Remove unnecessary a article (#9980)
Fix test_doc_example on big-endian systems (#9949)
fix weighted polyfit for arrays with more than 2 dimensions (#9974)
Use zarr-fixture to prevent thread leakage errors (#9967)
remove dask-expr from CI runs, fix related tests (#9971)
Update time coding tests to assert exact equality (#9961)
cast type to PDDatetimeUnitOptions (#9963)
Suggest the correct name when no key matches in the dataset (#9943)
fix upstream dev issues (#9953)
Relax nanosecond datetime restriction in CF time decoding (#9618)
Remove outdated quantile test. (#9945)
...
dcherian added a commit that referenced this pull request Jan 30, 2025
* main: (79 commits)
fix mean for datetime-like using the respective time resolution unit (#9977)
Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (#9965)
remove gate and add a test (#9958)
Remove repetitive that (replace it with the) (#9994)
add shxarray to the xarray ecosystem list (#9995)
Add `shards` to `valid_encodings` to enable sharded Zarr writing (#9948)
Use flox for grouped first, last (#9986)
Bump the actions group with 2 updates (#9989)
Fix some typing (#9988)
Remove unnecessary a article (#9980)
Fix test_doc_example on big-endian systems (#9949)
fix weighted polyfit for arrays with more than 2 dimensions (#9974)
Use zarr-fixture to prevent thread leakage errors (#9967)
remove dask-expr from CI runs, fix related tests (#9971)
Update time coding tests to assert exact equality (#9961)
cast type to PDDatetimeUnitOptions (#9963)
Suggest the correct name when no key matches in the dataset (#9943)
fix upstream dev issues (#9953)
Relax nanosecond datetime restriction in CF time decoding (#9618)
Remove outdated quantile test. (#9945)
...
wavebyrd pushed a commit to wavebyrd/xarray that referenced this pull request Mar 13, 2026
* main: (79 commits)
fix mean for datetime-like using the respective time resolution unit (pydata#9977)
Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (pydata#9965)
remove gate and add a test (pydata#9958)
Remove repetitive that (replace it with the) (pydata#9994)
add shxarray to the xarray ecosystem list (pydata#9995)
Add `shards` to `valid_encodings` to enable sharded Zarr writing (pydata#9948)
Use flox for grouped first, last (pydata#9986)
Bump the actions group with 2 updates (pydata#9989)
Fix some typing (pydata#9988)
Remove unnecessary a article (pydata#9980)
Fix test_doc_example on big-endian systems (pydata#9949)
fix weighted polyfit for arrays with more than 2 dimensions (pydata#9974)
Use zarr-fixture to prevent thread leakage errors (pydata#9967)
remove dask-expr from CI runs, fix related tests (pydata#9971)
Update time coding tests to assert exact equality (pydata#9961)
cast type to PDDatetimeUnitOptions (pydata#9963)
Suggest the correct name when no key matches in the dataset (pydata#9943)
fix upstream dev issues (pydata#9953)
Relax nanosecond datetime restriction in CF time decoding (pydata#9618)
Remove outdated quantile test. (pydata#9945)
...
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.

Averaging timestamps with non-nanosecond precision

4 participants

@kmuehlbauer@sfinkens@dcherian@spencerkclark