Skip to content
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

Enhance and move ISO-8601 parser to coding.times #9899

Merged
merged 21 commits into from
Dec 31, 2024

Conversation

kmuehlbauer
Copy link
Contributor

@kmuehlbauer kmuehlbauer commented Dec 17, 2024

This enhances the ISO-8601 parser to check for signed years (eg, -0300 or +0010) as well as 5 digit years (eg. -10000, +20000, 10000). The relevant parsing code is moved to coding.times (to prevent circular import) as these functionality will be used in #9618 within coding.times.

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

@kmuehlbauer kmuehlbauer marked this pull request as ready for review December 17, 2024 11:01
@kmuehlbauer
Copy link
Contributor Author

@dcherian Thanks for the review, I've addressed according your comments and suggestions.

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 @kmuehlbauer—this looks nice. I guess so long as we accept a flexible number of digits in the year it will be hard to extend beyond five-digit years, which is totally fine for now.

Per @dcherian's TODO, I tried my hand at adding a hypothesis strategy for generating cftime objects in kmuehlbauer#2.

xarray/tests/test_cftimeindex.py Outdated Show resolved Hide resolved
doc/whats-new.rst Outdated Show resolved Hide resolved
doc/whats-new.rst Outdated Show resolved Hide resolved
@spencerkclark spencerkclark added the run-slow-hypothesis Run slow hypothesis tests label Dec 29, 2024
Copy link
Collaborator

@headtr1ck headtr1ck left a comment

Choose a reason for hiding this comment

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

Let's take the opportunity and add some typing.

But looks good, thanks.

xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/tests/test_cftimeindex.py Outdated Show resolved Hide resolved
xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/coding/times.py Outdated Show resolved Hide resolved
xarray/coding/cftimeindex.py Show resolved Hide resolved
@kmuehlbauer
Copy link
Contributor Author

Let's take the opportunity and add some typing.

Thanks @headtr1ck for the review and typing addendum.

@kmuehlbauer
Copy link
Contributor Author

Per @dcherian's TODO, I tried my hand at adding a hypothesis strategy for generating cftime objects in kmuehlbauer#2.

Thanks @spencerkclark for reviewing and the additions!

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 @kmuehlbauer! Though it passes CI, I'm happy to iterate further on the hypothesis portion in this or a follow-up PR if needed. It's fairly low-stakes / orthogonal to the main contribution.

return self.min_value + datetime.timedelta(microseconds=result)


class CFTimeStrategyISO8601(st.SearchStrategy):
Copy link
Contributor

Choose a reason for hiding this comment

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

@spencerkclark very nice!

I think the idiomatic way is to use composite but we can do that later.

@dcherian dcherian merged commit b14080e into pydata:main Dec 31, 2024
29 checks passed
@kmuehlbauer kmuehlbauer deleted the iso-parser branch January 2, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-slow-hypothesis Run slow hypothesis tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants