-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API/ENH: tz_localize handling of nonexistent times: rename keyword + add shift option #22644
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
Changes from 58 commits
bf5e7bf
36d13c7
a5ea445
8753d00
e1a6c6a
a7c86c8
1884c7b
a6a05df
c4dc8aa
1bc81db
c81d58c
b2c8429
a65987d
710014c
93159e5
a0ffcdd
219256f
d435481
7c849b6
56ac4fe
b7b09bd
94a72a5
39b769e
18664d8
8852d43
38b95e9
c88b0d8
1bae682
d30f891
f337692
6a12a7e
a7b8357
7ad87ec
abad726
6be1c25
f8be4b6
c192c9f
8909f38
49f203f
01678c7
707fdde
ae27a50
85ed25e
9041ebe
a4cdac2
0a9c1db
efb382e
61c73ca
20cc925
394a0db
a5253ee
5185683
ba1bfed
8b06c96
42ae923
fe575fe
3482f92
f0e43e2
b98d4cf
e6c5b2d
83423ad
1ca0ab2
5bcc977
8cf16e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,14 +564,26 @@ class NaTType(_NaT): | |
- 'NaT' will return NaT for an ambiguous time | ||
- 'raise' will raise an AmbiguousTimeError for an ambiguous time | ||
|
||
errors : 'raise', 'coerce', default 'raise' | ||
nonexistent : 'shift', 'NaT', default 'raise' | ||
A nonexistent time doesn't not exist in a particular timezone | ||
where clocks moved forward due to DST. | ||
|
||
- 'shift' will shift the nonexistent time forward to the closest | ||
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. Sorry, rst formatting nitpick: there needs to be a blank line between the first sentences, and the start of this list ... (getting rst right can be annoying ..) |
||
existing time | ||
- 'NaT' will return NaT where there are nonexistent times | ||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 'raise' will raise an NonExistentTimeError if there are | ||
nonexistent times | ||
|
||
.. versionadded:: 0.24.0 | ||
|
||
errors : 'raise', 'coerce', default None | ||
- 'raise' will raise a NonExistentTimeError if a timestamp is not | ||
valid in the specified timezone (e.g. due to a transition from | ||
or to DST time) | ||
or to DST time). Use ``nonexistent='raise'`` instead. | ||
- 'coerce' will return NaT if the timestamp can not be converted | ||
into the specified timezone | ||
into the specified timezone. Use ``nonexistent='NaT'`` instead. | ||
|
||
.. versionadded:: 0.19.0 | ||
.. deprecated:: 0.24.0 | ||
|
||
Returns | ||
------- | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -961,7 +961,8 @@ class Timestamp(_Timestamp): | |||||
def is_leap_year(self): | ||||||
return bool(ccalendar.is_leapyear(self.year)) | ||||||
|
||||||
def tz_localize(self, tz, ambiguous='raise', errors='raise'): | ||||||
def tz_localize(self, tz, ambiguous='raise', nonexistent='raise', | ||||||
errors=None): | ||||||
""" | ||||||
Convert naive Timestamp to local time zone, or remove | ||||||
timezone from tz-aware Timestamp. | ||||||
|
@@ -978,14 +979,26 @@ class Timestamp(_Timestamp): | |||||
- 'NaT' will return NaT for an ambiguous time | ||||||
- 'raise' will raise an AmbiguousTimeError for an ambiguous time | ||||||
|
||||||
errors : 'raise', 'coerce', default 'raise' | ||||||
nonexistent : 'shift', 'NaT', default 'raise' | ||||||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
A nonexistent time doesn't not exist in a particular timezone | ||||||
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.
Suggested change
|
||||||
where clocks moved forward due to DST. | ||||||
|
||||||
- 'shift' will shift the nonexistent time forward to the closest | ||||||
existing time | ||||||
- 'NaT' will return NaT where there are nonexistent times | ||||||
- 'raise' will raise an NonExistentTimeError if there are | ||||||
nonexistent times | ||||||
|
||||||
.. versionadded:: 0.24.0 | ||||||
|
||||||
errors : 'raise', 'coerce', default None | ||||||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- 'raise' will raise a NonExistentTimeError if a timestamp is not | ||||||
valid in the specified timezone (e.g. due to a transition from | ||||||
or to DST time) | ||||||
or to DST time). Use ``nonexistent='raise'`` instead. | ||||||
- 'coerce' will return NaT if the timestamp can not be converted | ||||||
into the specified timezone | ||||||
into the specified timezone. Use ``nonexistent='NaT'`` instead. | ||||||
|
||||||
.. versionadded:: 0.19.0 | ||||||
.. deprecated:: 0.24.0 | ||||||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Returns | ||||||
------- | ||||||
|
@@ -999,13 +1012,26 @@ class Timestamp(_Timestamp): | |||||
if ambiguous == 'infer': | ||||||
raise ValueError('Cannot infer offset with only one time.') | ||||||
|
||||||
if errors is not None: | ||||||
warnings.warn("The errors argument is deprecated and will be " | ||||||
"removed in a future release. Use " | ||||||
"nonexistent='NaT' or nonexistent='raise' " | ||||||
"instead.", FutureWarning) | ||||||
if errors == 'coerce': | ||||||
nonexistent = 'NaT' | ||||||
elif errors == 'raise': | ||||||
nonexistent = 'raise' | ||||||
else: | ||||||
raise ValueError("The errors argument must be either coerce " | ||||||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
"or raise.") | ||||||
if self.tzinfo is None: | ||||||
# tz naive, localize | ||||||
tz = maybe_get_tz(tz) | ||||||
if not is_string_object(ambiguous): | ||||||
ambiguous = [ambiguous] | ||||||
value = tz_localize_to_utc(np.array([self.value], dtype='i8'), tz, | ||||||
ambiguous=ambiguous, errors=errors)[0] | ||||||
ambiguous=ambiguous, | ||||||
nonexistent=nonexistent)[0] | ||||||
return Timestamp(value, tz=tz) | ||||||
else: | ||||||
if tz is None: | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.