-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Datetime parsing (PDEP-4): allow mixture of ISO formatted strings #50939
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 8 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
044948f
allow format iso8601
f4e1392
fixup tests
9f06d80
:label: typing
d7f6056
remove duplicate code
8952a0e
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
6e6d579
improve message, use if-statement
3d65dbf
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
b247bbd
note that exact has no effect if format=iso8601
2f66f87
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
eb36d8c
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
262be89
point to format=ISO8601 in error message
e01b6ee
allow format="mixed"
4a61e6a
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
607c77d
link to iso wiki page
531e0e8
Merge remote-tracking branch 'upstream/main' into allow-mixed-iso
5582882
Merge branch 'main' into allow-mixed-iso
MarcoGorelli 57b922c
Merge branch 'main' into allow-mixed-iso
MarcoGorelli 313003e
minor fixups
2ede506
Merge branch 'main' into allow-mixed-iso
MarcoGorelli 3b61e5b
double backticks -> single, suggest passing format
acd44ae
use format=mixed instead of apply in example;
ba6393f
Merge branch 'main' into allow-mixed-iso
mroeschke 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,11 +442,15 @@ def _convert_listlike_datetimes( | |
|
||
arg = ensure_object(arg) | ||
|
||
format_inferred = False | ||
if format is None: | ||
format = _guess_datetime_format_for_array(arg, dayfirst=dayfirst) | ||
format_inferred = True | ||
|
||
if format is not None: | ||
return _array_strptime_with_fallback(arg, name, utc, format, exact, errors) | ||
return _array_strptime_with_fallback( | ||
arg, name, utc, format, format_inferred, exact, errors | ||
) | ||
|
||
result, tz_parsed = objects_to_datetime64ns( | ||
arg, | ||
|
@@ -471,13 +475,16 @@ def _array_strptime_with_fallback( | |
name, | ||
utc: bool, | ||
fmt: str, | ||
fmt_inferred: bool, | ||
exact: bool, | ||
errors: str, | ||
) -> Index: | ||
""" | ||
Call array_strptime, with fallback behavior depending on 'errors'. | ||
""" | ||
result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc) | ||
result, timezones = array_strptime( | ||
arg, fmt, fmt_inferred=fmt_inferred, exact=exact, errors=errors, utc=utc | ||
) | ||
if any(tz is not None for tz in timezones): | ||
return _return_parsed_timezone_results(result, timezones, utc, name) | ||
|
||
|
@@ -759,13 +766,15 @@ def to_datetime( | |
<https://docs.python.org/3/library/datetime.html | ||
#strftime-and-strptime-behavior>`_ for more information on choices, though | ||
note that :const:`"%f"` will parse all the way up to nanoseconds. | ||
You can also pass "ISO8601" to parse any ISO8601 time string. | ||
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. Add a link that explains ISO8601? (eg https://en.wikipedia.org/wiki/ISO_8601) Although looking at that link makes me wonder if we then should be explicit about that this is only the calendar date + time formatting (and not week dates or ordinal dates) |
||
exact : bool, default True | ||
Control how `format` is used: | ||
|
||
- If :const:`True`, require an exact `format` match. | ||
- If :const:`False`, allow the `format` to match anywhere in the target | ||
string. | ||
|
||
Note that if ``format='ISO8601'`` then `exact` has no effect. | ||
unit : str, default 'ns' | ||
The unit of the arg (D,s,ms,us,ns) denote the unit, which is an | ||
integer or float number. This will be based off the origin. | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any particular reason this is changed from failed? doesn't really matter to me, just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it just simplifies the logic