-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Support datetime.timezone objects #25065
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 23 commits
8ff8024
4ade114
8ff047b
5076045
f819b26
98c3fd2
224fcc9
b3634f4
2a082ed
bfb2fd3
35b475e
a8f163e
07e9b57
fcf84ae
6d9af30
af64d24
f052721
ac34a1b
12e163d
a98d1fa
c3d01bf
9f44011
6649396
b8354c2
d74673e
c0ad4b4
96e068b
67de9c0
956822d
a843ae1
1c6165b
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ Other Enhancements | |
- ``Series.str`` has gained :meth:`Series.str.casefold` method to removes all case distinctions present in a string (:issue:`25405`) | ||
- :meth:`DataFrame.set_index` now works for instances of ``abc.Iterator``, provided their output is of the same length as the calling frame (:issue:`22484`, :issue:`24984`) | ||
- :meth:`DatetimeIndex.union` now supports the ``sort`` argument. The behaviour of the sort parameter matches that of :meth:`Index.union` (:issue:`24994`) | ||
- | ||
- :meth:`datetime.timezone` objects are now supported as arguments to timezone methods and constructors (:issue:`25065`) | ||
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. meth -> class (not sure if it matters). |
||
|
||
.. _whatsnew_0250.api_breaking: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
from datetime import timezone | ||
|
||
# dateutil compat | ||
from dateutil.tz import ( | ||
|
@@ -23,11 +24,12 @@ from pandas._libs.tslibs.util cimport ( | |
is_string_object, is_integer_object, get_nat) | ||
|
||
cdef int64_t NPY_NAT = get_nat() | ||
cdef object utc_stdlib = timezone.utc | ||
|
||
# ---------------------------------------------------------------------- | ||
|
||
cpdef inline bint is_utc(object tz): | ||
return tz is UTC or isinstance(tz, _dateutil_tzutc) | ||
return tz is UTC or isinstance(tz, _dateutil_tzutc) or tz is utc_stdlib | ||
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. Potential micro optimization: I suspect that |
||
|
||
|
||
cdef inline bint is_tzlocal(object tz): | ||
|
@@ -167,6 +169,8 @@ cdef inline bint is_fixed_offset(object tz): | |
return 1 | ||
else: | ||
return 0 | ||
# This also implicitly accepts datetime.timezone objects which are | ||
# considered fixed | ||
return 1 | ||
|
||
|
||
|
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.
I think that :class:
datetime.timezone
will work.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.
Looks like there are a few more mentions of what's supported