-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
implement _local_timestamps in DatetimeArrayMixin #21721
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,10 @@ | |
import warnings | ||
|
||
import numpy as np | ||
from pytz import utc | ||
|
||
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 | ||
|
||
|
@@ -108,3 +109,22 @@ def _sub_datelike_dti(self, other): | |
mask = (self._isnan) | (other._isnan) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this only make sense if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah not sure why that indexer is there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the next pass I'll see if this can be simplified. |
||
|
||
n = len(indexer) | ||
reverse = np.empty(n, dtype=np.int_) | ||
reverse.put(indexer, np.arange(n)) | ||
return result.take(reverse) |
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 a doc-string here (e.g. what are the return guarantees here)