-
-
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
ENH: Support datetime.timezone objects #25065
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25065 +/- ##
=======================================
Coverage 92.37% 92.37%
=======================================
Files 166 166
Lines 52403 52403
=======================================
Hits 48405 48405
Misses 3998 3998
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25065 +/- ##
=======================================
Coverage 91.25% 91.25%
=======================================
Files 172 172
Lines 52977 52977
=======================================
Hits 48342 48342
Misses 4635 4635
Continue to review full report at Codecov.
|
pandas/_libs/tslibs/timezones.pyx
Outdated
@@ -27,7 +28,7 @@ cdef int64_t NPY_NAT = get_nat() | |||
# ---------------------------------------------------------------------- | |||
|
|||
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 timezone.utc |
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.
Consider “cdef tzinfo utc_stdlib = timezone.utc” at module level. Much faster lookup for frequently-done check.
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.
Wasn't able to cdef with tzinfo
(used object
instead). Would it tzinfo
have to be cimport
ed?
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.
Would it tzinfo have to be cimported?
Yah, that shouldn't be a problem though. We do it elsewhere.
Python 2 builds are failing as expected. By virtue of the tz_fixtures,
|
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -20,7 +20,7 @@ Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
- :meth:`Timestamp.replace` now supports the ``fold`` argument to disambiguate DST transition times (:issue:`25017`) | |||
- | |||
- ``datetime.timezone`` objects are now supported (:issue:`25065`) |
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.
can you add a :meth: with a ref to the python docs
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.
add where they are supported
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.
LGTM, minor nitpicks if you have a chance.
doc/source/user_guide/timeseries.rst
Outdated
@@ -2149,12 +2149,9 @@ Time Zone Handling | |||
------------------ | |||
|
|||
pandas provides rich support for working with timestamps in different time | |||
zones using the ``pytz`` and ``dateutil`` libraries. | |||
zones using the ``pytz`` and ``dateutil`` libraries or ``datetime.timezone`` |
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
- Reword L272 to include datetime.timezone
- Add a daetetime.timezone example in the example ~L2181
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
meth -> class (not sure if it matters).
pandas/_libs/tslibs/timezones.pyx
Outdated
|
||
# ---------------------------------------------------------------------- | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Potential micro optimization: I suspect that tz is utc_stdlib
is relatively cheap compared to isinstance(tz, _dateutil_tzutc)
. Maybe swap the order of those two for a better average case? Not sure if this matters.
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.
LGTM. I'd say merge later today if there are no objections.
pandas/_libs/tslibs/timezones.pyx
Outdated
|
||
# ---------------------------------------------------------------------- | ||
|
||
cpdef inline bint is_utc(object tz): | ||
return tz is UTC or isinstance(tz, _dateutil_tzutc) | ||
return tz is UTC or or tz is utc_stdlib or isinstance(tz, _dateutil_tzutc) |
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.
Whoops, an extra or
here.
@TomAugspurger This branch will always fail the PY2 builds though (feature introduced in 3.3). I was thinking we wait until those builds are removed (hopefully soonish/after 0.24.2) |
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.
minor comment, otherwise lgtm.
This should be good to merge now that the PY2 builds are gone. |
thanks @mroeschke |
* origin/master: DOC: clean bug fix section in whatsnew (pandas-dev#25792) DOC: Fixed PeriodArray api ref (pandas-dev#25526) Move locale code out of tm, into _config (pandas-dev#25757) Unpin pycodestyle (pandas-dev#25789) Add test for rdivmod on EA array (GH23287) (pandas-dev#24047) ENH: Support datetime.timezone objects (pandas-dev#25065) Cython language level 3 (pandas-dev#24538) API: concat on sparse values (pandas-dev#25719) TST: assert_produces_warning works with filterwarnings (pandas-dev#25721) make core.config self-contained (pandas-dev#25613) CLN: replace %s syntax with .format in pandas.io.parsers (pandas-dev#24721) TST: Check pytables<3.5.1 when skipping (pandas-dev#25773) DOC: Fix typo in docstring of DataFrame.memory_usage (pandas-dev#25770) Replace dicts with OrderedDicts in groupby aggregation functions (pandas-dev#25693) TST: Fixturize tests/frame/test_missing.py (pandas-dev#25640) DOC: Improve the docsting of Series.iteritems (pandas-dev#24879) DOC: Fix function name. (pandas-dev#25751) Implementing iso_week_year support for to_datetime (pandas-dev#25541) DOC: clarify corr behaviour when using a callable (pandas-dev#25732) remove unnecessary check_output (pandas-dev#25755) # Conflicts: # doc/source/whatsnew/v0.25.0.rst
* upstream/master: (55 commits) PERF: Improve performance of StataReader (pandas-dev#25780) Speed up tokenizing of a row in csv and xstrtod parsing (pandas-dev#25784) BUG: Fix _binop for operators for serials which has more than one returns (divmod/rdivmod). (pandas-dev#25588) BUG-24971 copying blocks also considers ndim (pandas-dev#25521) CLN: Panel reference from documentation (pandas-dev#25649) ENH: Quoting column names containing spaces with backticks to use them in query and eval. (pandas-dev#24955) BUG: reading windows utf8 filenames in py3.6 (pandas-dev#25769) DOC: clean bug fix section in whatsnew (pandas-dev#25792) DOC: Fixed PeriodArray api ref (pandas-dev#25526) Move locale code out of tm, into _config (pandas-dev#25757) Unpin pycodestyle (pandas-dev#25789) Add test for rdivmod on EA array (GH23287) (pandas-dev#24047) ENH: Support datetime.timezone objects (pandas-dev#25065) Cython language level 3 (pandas-dev#24538) API: concat on sparse values (pandas-dev#25719) TST: assert_produces_warning works with filterwarnings (pandas-dev#25721) make core.config self-contained (pandas-dev#25613) CLN: replace %s syntax with .format in pandas.io.parsers (pandas-dev#24721) TST: Check pytables<3.5.1 when skipping (pandas-dev#25773) DOC: Fix typo in docstring of DataFrame.memory_usage (pandas-dev#25770) ...
git diff upstream/master -u -- "*.py" | flake8 --diff
Introduced in Python 3.2. First pass is to evaluate what tests fail when included in the tz_aware_fixture