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
|
|
||
| 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.
Consider “cdef tzinfo utc_stdlib = timezone.utc” at module level. Much faster lookup for frequently-done check.
There was a problem hiding this comment.
Wasn't able to cdef with tzinfo (used object instead). Would it tzinfo have to be cimported?
There was a problem hiding this comment.
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
|
|
||
| - :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.
can you add a :meth: with a ref to the python docs
There was a problem hiding this comment.
add where they are supported
TomAugspurger
left a comment
There was a problem hiding this comment.
LGTM, minor nitpicks if you have a chance.
doc/source/user_guide/timeseries.rst
Outdated
|
|
||
| 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.
I think that :class:datetime.timezone will work.
There was a problem hiding this comment.
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
| - :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.
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.
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.
TomAugspurger
left a comment
There was a problem hiding this comment.
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.
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) |
jreback
left a comment
There was a problem hiding this comment.
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
git diff upstream/master -u -- "*.py" | flake8 --diffIntroduced in Python 3.2. First pass is to evaluate what tests fail when included in the tz_aware_fixture