Skip to content

Fix convert calendar on non-temporal data in datasets #10268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

aulemahal
Copy link
Contributor

When calling convert_calendar on dataset with non-temporal variable (no time dimension), the time dimension was added. This is because the function was using where(time.notnull(), drop=True) to drop the time elements of the source that did not map to a valid time in the target calendar.

Given that time is always 1D and always loaded (no dask), using sel(time=time.notnull()) fixes the bug, and, in fact, makes more sense to me. (I don't remember why I didn't use that in my first version of the method...)

I added a minimal test that detects the bug raised in the issue.

Copy link
Member

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

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

Thanks @aulemahal—this makes more sense to me too!

@spencerkclark spencerkclark added the plan to merge Final call for comments label Apr 29, 2025
@dcherian dcherian merged commit d7a6f2b into pydata:main Apr 29, 2025
36 of 38 checks passed
dcherian added a commit to dcherian/xarray that referenced this pull request Apr 29, 2025
* main:
  Fix convert calendar on non-temporal data in datasets (pydata#10268)
  BinGrouper: reduce indirection (pydata#10270)
  Fix reduction by subset of grouper dimensions (pydata#10258)
  Shorten text repr for ``DataTree`` (pydata#10139)
  Fix benchmarks runners (pydata#10265)
  Fix infinite recursion when calling `np.fix` (pydata#10248)
  BinGrouper: Support setting labels when provided with IntervalIndex (pydata#10259)
  Avoid stacking when grouping by chunked array (pydata#10254)
  Improve alignment checks (pydata#10251)
  Update how-to-add-new-backend.rst (pydata#10240)
  Support extension array indexes (pydata#9671)
  Switch documentation to pydata-sphinx-theme (pydata#8708)
  Bump codecov/codecov-action from 5.4.0 to 5.4.2 in the actions group (pydata#10239)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

convert_calendar adds a time dimension to all variables
3 participants