-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhance and move ISO-8601 parser to coding.times #9899
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
453b631
enhance and move iso-8601-parser to coding.times
kmuehlbauer e358a30
enhance test for iso 8601 parser
kmuehlbauer c395bc8
add whats-new.rst entry
kmuehlbauer 88573ba
add datetime property test
dcherian dd16f39
Apply suggestions from code review
kmuehlbauer fc86160
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0af4ff1
fix test
kmuehlbauer 23b2597
Merge branch 'main' into iso-parser
kmuehlbauer d733cc5
Merge branch 'main' into iso-parser
kmuehlbauer a6f41c0
Update xarray/tests/test_cftimeindex.py
kmuehlbauer a2de307
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3eb8ba7
Update doc/whats-new.rst
kmuehlbauer 2687750
Merge branch 'main' into iso-parser
kmuehlbauer 81d44ef
Add hypothesis strategy for cftime objects (#2)
spencerkclark 1d6b663
Merge branch 'main' into iso-parser
kmuehlbauer f7340c4
Fix doc build
spencerkclark bd0825b
Apply suggestions from code review
kmuehlbauer 8a4d1af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2224486
Merge branch 'main' into iso-parser
kmuehlbauer 616a7e3
fix typing
kmuehlbauer c61f2ce
rename _parse_iso8601_with_reso to _parse_iso8601, remove _parse_iso8…
kmuehlbauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import datetime | ||
import warnings | ||
from collections.abc import Hashable, Iterable, Mapping, Sequence | ||
from typing import TYPE_CHECKING, Any, Protocol, overload | ||
|
||
|
@@ -473,3 +475,36 @@ def unique_subset_of( | |
return ( | ||
{k: objs[k] for k in subset_keys} if isinstance(objs, Mapping) else subset_keys | ||
) | ||
|
||
|
||
class CFTimeStategy(st.SearchStrategy): | ||
def __init__(self, min_value, max_value): | ||
self.min_value = min_value | ||
self.max_value = max_value | ||
|
||
def do_draw(self, data): | ||
unit_microsecond = datetime.timedelta(microseconds=1) | ||
timespan_microseconds = (self.max_value - self.min_value) // unit_microsecond | ||
result = data.draw_integer(0, timespan_microseconds) | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", message=".*date/calendar/year zero.*") | ||
return self.min_value + datetime.timedelta(microseconds=result) | ||
|
||
|
||
class CFTimeStrategyISO8601(st.SearchStrategy): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
def __init__(self): | ||
from xarray.tests.test_coding_times import _all_cftime_date_types | ||
|
||
self.date_types = _all_cftime_date_types() | ||
self.calendars = list(self.date_types) | ||
|
||
def do_draw(self, data): | ||
calendar = data.draw(st.sampled_from(self.calendars)) | ||
date_type = self.date_types[calendar] | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", message=".*date/calendar/year zero.*") | ||
daysinmonth = date_type(99999, 12, 1).daysinmonth | ||
min_value = date_type(-99999, 1, 1) | ||
max_value = date_type(99999, 12, daysinmonth, 23, 59, 59, 999999) | ||
strategy = CFTimeStategy(min_value, max_value) | ||
return strategy.do_draw(data) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.