8000 PERF: Use is_utc check to improve performance of dateutil UTC in DatetimeIndex methods by mroeschke · Pull Request #23772 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
10000

PERF: Use is_utc check to improve performance of dateutil UTC in DatetimeIndex methods #23772

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

Merged
merged 9 commits into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
PERF: DatetimeIndex attribute access with dateutil UTC
  • Loading branch information
Matt Roeschke committed Nov 18, 2018
commit da9d0d0dd1b635451f823aa337afe0fe1673c00c
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timezones.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

cdef bint is_utc(object tz)
cpdef bint is_utc(object tz)
cdef bint is_tzlocal(object tz)

cdef bint treat_tz_as_pytz(object tz)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef int64_t NPY_NAT = get_nat()

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

cdef inline bint is_utc(object tz):
cpdef inline bint is_utc(object tz):
return tz is UTC or isinstance(tz, _dateutil_tzutc)


Expand Down
13 changes: 6 additions & 7 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ def _to_m8(key, tz=None):
def _field_accessor(name, field, docstring=None):
def f(self):
values = self.asi8
if self.tz is not None:
if self.tz is not utc:
values = self._local_timestamps()
if self.tz is not None and not timezones.is_utc(self.tz):
values = self._local_timestamps()

if field in self._bool_ops:
if field.endswith(('start', 'end')):
Expand Down Expand Up @@ -966,7 +965,7 @@ def month_name(self, locale=None):
>>> idx.month_name()
Index(['January', 'February', 'March'], dtype='object')
"""
if self.tz is not None and self.tz is not utc:
if self.tz is not None and not timezones.is_utc(self.tz):
values = self._local_timestamps()
else:
values = self.asi8
Expand Down Expand Up @@ -1002,7 +1001,7 @@ def day_name(self, locale=None):
>>> idx.day_name()
Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
"""
if self.tz is not None and self.tz is not utc:
if self.tz is not None and not timezones.is_utc(self.tz):
values = self._local_timestamps()
else:
values = self.asi8
Expand All @@ -1020,7 +1019,7 @@ def time(self):
# If the Timestamps have a timezone that is not UTC,
# convert them into their i8 representation while
# keeping their timezone and not using UTC
if self.tz is not None and self.tz is not utc:
if self.tz is not None and not timezones.is_utc(self.tz):
timestamps = self._local_timestamps()
else:
timestamps = self.asi8
Expand All @@ -1044,7 +1043,7 @@ def date(self):
# If the Timestamps have a timezone that is not UTC,
# convert them into their i8 representation while
# keeping their timezone and not using UTC
if self.tz is not None and self.tz is not utc:
if self.tz is not None and not timezones.is_utc(self.tz):
timestamps = self._local_timestamps()
else:
timestamps = self.asi8
Expand Down
0