Skip to content
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

Merged
merged 31 commits into from Mar 19, 2019

Conversation

@mroeschke
Copy link
Member

commented Jan 31, 2019

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Introduced in Python 3.2. First pass is to evaluate what tests fail when included in the tz_aware_fixture

@codecov

This comment has been minimized.

Copy link

commented Feb 1, 2019

Codecov Report

Merging #25065 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #25065   +/-   ##
=======================================
  Coverage   92.37%   92.37%           
=======================================
  Files         166      166           
  Lines       52403    52403           
=======================================
  Hits        48405    48405           
  Misses       3998     3998
Flag Coverage Δ
#multiple 90.79% <ø> (ø) ⬆️
#single 42.87% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea013a2...5076045. Read the comment docs.

@codecov

This comment has been minimized.

Copy link

commented Feb 1, 2019

Codecov Report

Merging #25065 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #25065   +/-   ##
=======================================
  Coverage   91.25%   91.25%           
=======================================
  Files         172      172           
  Lines       52977    52977           
=======================================
  Hits        48342    48342           
  Misses       4635     4635
Flag Coverage Δ
#multiple 89.82% <ø> (ø) ⬆️
#single 41.74% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 707c720...1c6165b. Read the comment docs.

Matt Roeschke
@@ -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

This comment has been minimized.

Copy link
@jbrockmendel

jbrockmendel Feb 3, 2019

Member

Consider “cdef tzinfo utc_stdlib = timezone.utc” at module level. Much faster lookup for frequently-done check.

This comment has been minimized.

Copy link
@mroeschke

mroeschke Feb 3, 2019

Author Member

Wasn't able to cdef with tzinfo (used object instead). Would it tzinfo have to be cimported?

This comment has been minimized.

Copy link
@jbrockmendel

jbrockmendel Feb 3, 2019

Member

Would it tzinfo have to be cimported?

Yah, that shouldn't be a problem though. We do it elsewhere.

@mroeschke

This comment has been minimized.

Copy link
Member Author

commented Feb 3, 2019

Python 2 builds are failing as expected.

By virtue of the tz_fixtures, datetime.timezones are now being tested with

  • DatetimeIndex & Timestamp & date_range & Series constructor
  • DatetimeIndex & Timestamp methods
  • timezone conversion
  • indexing
  • comparison and arithmetic ops with arrays & scalars
  • append/concat & other reshaping methods
  • NaT ops

@mroeschke mroeschke changed the title [WIP] ENH: Support datetime.timezone objects ENH: Support datetime.timezone objects Feb 3, 2019

Matt Roeschke

@mroeschke mroeschke added this to the 0.25.0 milestone Feb 3, 2019

@@ -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`)

This comment has been minimized.

Copy link
@jreback

jreback Feb 4, 2019

Contributor

can you add a :meth: with a ref to the python docs

This comment has been minimized.

Copy link
@jreback

jreback Feb 4, 2019

Contributor

add where they are supported

Matt Roeschke added some commits Feb 17, 2019

@TomAugspurger
Copy link
Contributor

left a comment

LGTM, minor nitpicks if you have a chance.

@@ -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``

This comment has been minimized.

Copy link
@TomAugspurger

TomAugspurger Mar 5, 2019

Contributor

I think that :class:datetime.timezone will work.

This comment has been minimized.

Copy link
@TomAugspurger

TomAugspurger Mar 5, 2019

Contributor

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
@@ -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`)

This comment has been minimized.

Copy link
@TomAugspurger

TomAugspurger Mar 5, 2019

Contributor

meth -> class (not sure if it matters).


# ----------------------------------------------------------------------

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

This comment has been minimized.

Copy link
@TomAugspurger

TomAugspurger Mar 5, 2019

Contributor

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.

Matt Roeschke added some commits Mar 5, 2019

@TomAugspurger
Copy link
Contributor

left a comment

LGTM. I'd say merge later today if there are no objections.


# ----------------------------------------------------------------------

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)

This comment has been minimized.

Copy link
@TomAugspurger

TomAugspurger Mar 5, 2019

Contributor

Whoops, an extra or here.

Matt Roeschke
@mroeschke

This comment has been minimized.

Copy link
Member Author

commented Mar 5, 2019

@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

jreback approved these changes Mar 5, 2019

Copy link
Contributor

left a comment

minor comment, otherwise lgtm.

Show resolved Hide resolved doc/source/user_guide/timeseries.rst

Matt Roeschke added some commits Mar 5, 2019

@mroeschke

This comment has been minimized.

Copy link
Member Author

commented Mar 18, 2019

This should be good to merge now that the PY2 builds are gone.

@jreback jreback merged commit 9ab270f into pandas-dev:master Mar 19, 2019

8 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
pandas-dev.pandas Build #20190317.16 succeeded
Details
pandas-dev.pandas (Checks_and_doc) Checks_and_doc succeeded
Details
pandas-dev.pandas (Linux py36_locale_slow) Linux py36_locale_slow succeeded
Details
pandas-dev.pandas (Linux py37_locale) Linux py37_locale succeeded
Details
pandas-dev.pandas (Linux py37_np_dev) Linux py37_np_dev succeeded
Details
pandas-dev.pandas (Windows py36_np14) Windows py36_np14 succeeded
Details
pandas-dev.pandas (macOS py35_macos) macOS py35_macos succeeded
Details
@jreback

This comment has been minimized.

Copy link
Contributor

commented Mar 19, 2019

thanks @mroeschke

@mroeschke mroeschke deleted the mroeschke:datetime_timezone_object_support branch Mar 19, 2019

sighingnow added a commit to sighingnow/pandas that referenced this pull request Mar 20, 2019

Merge remote-tracking branch 'origin/master' into fix-25557
* 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

thoo added a commit to thoo/pandas that referenced this pull request Mar 20, 2019

Merge remote-tracking branch 'upstream/master' into pivot
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.