diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index a5acc3d0e8593..e5159141d4b59 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -2,10 +2,11 @@ import warnings import numpy as np +from pytz import utc from pandas._libs import tslib from pandas._libs.tslib import Timestamp, NaT, iNaT -from pandas._libs.tslibs import timezones +from pandas._libs.tslibs import conversion, timezones from pandas.util._decorators import cache_readonly @@ -110,6 +111,25 @@ def _sub_datelike_dti(self, other): new_values[mask] = iNaT return new_values.view('timedelta64[ns]') + # ----------------------------------------------------------------- + # Timezone Conversion and Localization Methods + + def _local_timestamps(self): + """ + Convert to an i8 (unix-like nanosecond timestamp) representation + while keeping the local timezone and not using UTC. + This is used to calculate time-of-day information as if the timestamps + were timezone-naive. + """ + values = self.asi8 + indexer = values.argsort() + result = conversion.tz_convert(values.take(indexer), utc, self.tz) + + n = len(indexer) + reverse = np.empty(n, dtype=np.int_) + reverse.put(indexer, np.arange(n)) + return result.take(reverse) + # ---------------------------------------------------------------- # Conversion Methods - Vectorized analogues of Timedelta methods diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3494811cc3a9b..05f7af6383211 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -603,14 +603,7 @@ def _local_timestamps(self): if self.is_monotonic: return conversion.tz_convert(self.asi8, utc, self.tz) else: - values = self.asi8 - indexer = values.argsort() - result = conversion.tz_convert(values.take(indexer), utc, self.tz) - - n = len(indexer) - reverse = np.empty(n, dtype=np.int_) - reverse.put(indexer, np.arange(n)) - return result.take(reverse) + return DatetimeArrayMixin._local_timestamps(self) @classmethod def _simple_new(cls, values, name=None, freq=None, tz=None,