Skip to content

Keep timezone when selecting one element of a tz-aware index - #11898

Open
ptlnextdoor wants to merge 3 commits into
pydata:mainfrom
ptlnextdoor:fix/oss-xarray-9307
Open

ptlnextdoor wants to merge 3 commits into
pydata:mainfrom
ptlnextdoor:fix/oss-xarray-9307

Conversation

@ptlnextdoor

@ptlnextdoor ptlnextdoor commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

.isel() with a scalar on a timezone-aware datetime index returned a naive value, so the timezone was lost. PandasIndexingAdapter._convert_scalar turned a tz-aware pd.Timestamp into a naive np.datetime64. It now keeps the Timestamp in a 0-d object array, because datetime64 cannot hold a timezone.

A new regression test in xarray/tests/test_indexing.py fails before the fix and passes after it. I also ran test_indexing, test_variable, test_dataarray, test_dataset, test_indexes and test_coding_times, plus ruff check and format. All pass. I did not run the full suite.

AI disclosure: this PR was prepared with AI assistance (Claude, Anthropic).

Copilot AI balanced review requested due to automatic review settings November 17, 2026 00:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

PandasIndexingAdapter._convert_scalar converted a tz-aware pd.Timestamp
to a naive np.datetime64, so isel with a scalar dropped the timezone.
Return an object 0-d array holding the Timestamp instead.

Co-authored-by: Claude <noreply@anthropic.com>

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.

Calling .isel() on a timezone-aware dimension/index causes it to lose timezone information

2 participants