Repository navigation
Conversation
Both lookup paths now recognize `PeriodDtype`, and the NumPy subtype checks skip pandas extension dtypes. Field extraction and formatting preserve the period dtype when constructing a pandas Series from a `PeriodIndex` or `PeriodArray`. Periods use the proleptic Gregorian calendar, and missing periods are masked when extracting integer fields or deriving seasons. Regression tests cover period-valued data and coordinates, including dotted lookup and grouping. Fixes pydata#1565
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Reading the month from a period-valued time coordinate raises a TypeError through both
da.time.dt.monthandda["time.month"]. Grouping bytime.monthfails at the same lookup. The accessor and dotted coordinate lookup passed the pandas period dtype to NumPy's subtype checks. NumPy cannot interpret that dtype, so lookup failed before pandas could extract the requested field.Both lookup paths now recognize
PeriodDtype, and the NumPy subtype checks skip pandas extension dtypes. Field extraction and formatting preserve the period dtype when constructing a pandas Series from aPeriodIndexorPeriodArray. Periods use the proleptic Gregorian calendar, and missing periods are masked when extracting integer fields or deriving seasons. Regression tests cover period-valued data and coordinates, including dotted lookup and grouping.pytest -q xarray/tests/test_accessor_dt.py xarray/tests/test_dataset.pystopped before test collection because NumPy was missing.A run with the xarray _access_through_cftimeindex change reverted gave no clear result, so no test is shown to catch this bug.
The changed test xarray/tests/test_accessor_dt.py did not run here: the numpy module is not installed.
The changed test xarray/tests/test_dataset.py did not run here: the numpy module is not installed.
Closes #1565
Checklist
whats-new.rstapi.rstAI Disclosure
I have tested any AI-generated content in my PR.
No result recorded for the xarray _access_through_cftimeindex change backs this box.
I take responsibility for any AI-generated content in my PR.
Tools: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}
AI disclosure
AI was used for assistance.