-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Refactor timezones functions out of tslib #17274
Closed
Closed
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
19c9033
Refactor timezones functions out of tslib
jbrockmendel b0e36f3
flake8 fixup
jbrockmendel c78a23f
flake8 whitespace fixup
jbrockmendel 34f9551
Merge branch 'master' into tslibs-timezones
jbrockmendel 0930ed5
revert to using offsets.DateOffset instead of ABCDateOffset
jbrockmendel 77c1e3c
Merge branch 'tslibs-timezones' of https://github.com/jbrockmendel/pa…
jbrockmendel 13e481d
Add period_helper to period sources
jbrockmendel 1a62298
Address reviewer comments; revert non-central fixes
jbrockmendel e8d8a3a
Merge branch 'master' into tslibs-timezones
jbrockmendel 0c1ba13
missing comma
jbrockmendel ed2bd61
Merge branch 'tslibs-timezones' of https://github.com/jbrockmendel/pa…
jbrockmendel f29e6e5
Remove total_seconds from pxd
jbrockmendel bf7dc6e
Merge branch 'master' into tslibs-timezones
jbrockmendel fb4aaa9
Merge conflicts
jbrockmendel 5faff3b
Merge branch 'tslibs-timezones' of https://github.com/jbrockmendel/pa…
jbrockmendel 0540e77
dummy commit to force CI
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,19 +10,19 @@ from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray, | |
NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA) | ||
import numpy as np | ||
|
||
cdef extern from "datetime_helper.h": | ||
double total_seconds(object) | ||
|
||
from libc.stdlib cimport free | ||
|
||
from pandas import compat | ||
from pandas.compat import PY2 | ||
from pandas.core.dtypes.generic import ABCDateOffset | ||
|
||
cimport cython | ||
|
||
cdef extern from "datetime.h": | ||
void PyDateTime_IMPORT() | ||
|
||
from datetime cimport ( | ||
is_leapyear, | ||
PyDateTime_IMPORT, | ||
pandas_datetimestruct, | ||
pandas_datetimestruct_to_datetime, | ||
pandas_datetime_to_datetimestruct, | ||
|
@@ -32,16 +32,17 @@ from datetime cimport ( | |
cimport util, lib | ||
from lib cimport is_null_datetimelike, is_period | ||
from pandas._libs import tslib, lib | ||
from pandas._libs.tslib import (Timedelta, Timestamp, iNaT, | ||
NaT, _get_utcoffset) | ||
from tslib cimport ( | ||
maybe_get_tz, | ||
_is_utc, | ||
_is_tzlocal, | ||
from pandas._libs.tslib import Timestamp, iNaT, NaT | ||
from tslib cimport _nat_scalar_rules | ||
|
||
from tslibs.timezones cimport ( | ||
total_seconds, | ||
_get_utcoffset, | ||
_get_dst_info, | ||
_nat_scalar_rules) | ||
_is_tzlocal, | ||
_is_utc, | ||
maybe_get_tz) | ||
|
||
from pandas.tseries import offsets | ||
from pandas.core.tools.datetimes import parse_time_string | ||
from pandas.tseries import frequencies | ||
|
||
|
@@ -117,9 +118,16 @@ cdef extern from "period_helper.h": | |
|
||
initialize_daytime_conversion_factor_matrix() | ||
|
||
|
||
cpdef _is_tick(item): | ||
# offsets.Tick subclasses offsets.DateOffset and has a "_inc" attribute | ||
return isinstance(item, ABCDateOffset) and hasattr(item, "_inc") | ||
|
||
|
||
# Period logic | ||
#---------------------------------------------------------------------- | ||
|
||
# TODO: never used? | ||
cdef inline int64_t apply_mult(int64_t period_ord, int64_t mult): | ||
""" | ||
Get freq+multiple ordinal value from corresponding freq-only ordinal value. | ||
|
@@ -131,6 +139,7 @@ cdef inline int64_t apply_mult(int64_t period_ord, int64_t mult): | |
|
||
return (period_ord - 1) // mult | ||
|
||
# TODO: never used? | ||
cdef inline int64_t remove_mult(int64_t period_ord_w_mult, int64_t mult): | ||
""" | ||
Get freq-only ordinal value from corresponding freq+multiple ordinal. | ||
|
@@ -746,10 +755,9 @@ cdef class _Period(object): | |
return hash((self.ordinal, self.freqstr)) | ||
|
||
def _add_delta(self, other): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.Tick, Timedelta)): | ||
if isinstance(other, (timedelta, np.timedelta64)) or _is_tick(other): | ||
offset = frequencies.to_offset(self.freq.rule_code) | ||
if isinstance(offset, offsets.Tick): | ||
if _is_tick(offset): | ||
nanos = tslib._delta_to_nanoseconds(other) | ||
offset_nanos = tslib._delta_to_nanoseconds(offset) | ||
|
||
|
@@ -758,7 +766,7 @@ cdef class _Period(object): | |
return Period(ordinal=ordinal, freq=self.freq) | ||
msg = 'Input cannot be converted to Period(freq={0})' | ||
raise IncompatibleFrequency(msg.format(self.freqstr)) | ||
elif isinstance(other, offsets.DateOffset): | ||
elif isinstance(other, ABCDateOffset): | ||
freqstr = other.rule_code | ||
base = frequencies.get_base_alias(freqstr) | ||
if base == self.freq.rule_code: | ||
|
@@ -771,9 +779,7 @@ cdef class _Period(object): | |
|
||
def __add__(self, other): | ||
if isinstance(self, Period): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.Tick, offsets.DateOffset, | ||
Timedelta)): | ||
if isinstance(other, (timedelta, np.timedelta64, ABCDateOffset)): | ||
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.
|
||
return self._add_delta(other) | ||
elif other is NaT: | ||
return NaT | ||
|
@@ -789,9 +795,7 @@ cdef class _Period(object): | |
|
||
def __sub__(self, other): | ||
if isinstance(self, Period): | ||
if isinstance(other, (timedelta, np.timedelta64, | ||
offsets.Tick, offsets.DateOffset, | ||
Timedelta)): | ||
if isinstance(other, (timedelta, np.timedelta64, ABCDateOffset)): | ||
neg_other = -other | ||
return self + neg_other | ||
elif lib.is_integer(other): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
An upcoming PR will make a cython version of
dtypes.generic
. Theisinstance
checks are about 2x faster that way. It's a small difference, but nice to avoid calling into python for these things.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.
let's keep perf changes separate. I would much prefer PR's that don't mix multiple changes all at once.
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.
OK. I just pushed a commit that reverted from
ABCDateOffset
back tooffsets.DateOffset
.