-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Behaviour change in 1.5.0 when using Timedelta as Enum data type #49579
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 all commits
f64f476
8ee9a65
b48a4c0
3e1f67a
6821196
a6bdc33
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 |
---|---|---|
|
@@ -189,7 +189,7 @@ def ints_to_pytimedelta(ndarray m8values, box=False): | |
res_val = <object>NaT | ||
else: | ||
if box: | ||
res_val = _timedelta_from_value_and_reso(value, reso=reso) | ||
res_val = _timedelta_from_value_and_reso(Timedelta, value, reso=reso) | ||
elif reso == NPY_DATETIMEUNIT.NPY_FR_ns: | ||
res_val = timedelta(microseconds=int(value) / 1000) | ||
elif reso == NPY_DATETIMEUNIT.NPY_FR_us: | ||
|
@@ -741,7 +741,7 @@ cdef bint _validate_ops_compat(other): | |
def _op_unary_method(func, name): | ||
def f(self): | ||
new_value = func(self.value) | ||
return _timedelta_from_value_and_reso(new_value, self._creso) | ||
return _timedelta_from_value_and_reso(Timedelta, new_value, self._creso) | ||
f.__name__ = name | ||
return f | ||
|
||
|
@@ -804,7 +804,7 @@ def _binary_op_method_timedeltalike(op, name): | |
# TODO: more generally could do an overflowcheck in op? | ||
return NaT | ||
|
||
return _timedelta_from_value_and_reso(res, reso=self._creso) | ||
return _timedelta_from_value_and_reso(Timedelta, res, reso=self._creso) | ||
|
||
f.__name__ = name | ||
return f | ||
|
@@ -935,10 +935,10 @@ cdef _to_py_int_float(v): | |
|
||
|
||
def _timedelta_unpickle(value, reso): | ||
return _timedelta_from_value_and_reso(value, reso) | ||
return _timedelta_from_value_and_reso(Timedelta, value, reso) | ||
|
||
|
||
cdef _timedelta_from_value_and_reso(int64_t value, NPY_DATETIMEUNIT reso): | ||
cdef _timedelta_from_value_and_reso(cls, int64_t value, NPY_DATETIMEUNIT reso): | ||
# Could make this a classmethod if/when cython supports cdef classmethods | ||
cdef: | ||
_Timedelta td_base | ||
|
@@ -949,13 +949,13 @@ cdef _timedelta_from_value_and_reso(int64_t value, NPY_DATETIMEUNIT reso): | |
# We pass 0 instead, and override seconds, microseconds, days. | ||
# In principle we could pass 0 for ns and us too. | ||
if reso == NPY_FR_ns: | ||
td_base = _Timedelta.__new__(Timedelta, microseconds=int(value) // 1000) | ||
td_base = _Timedelta.__new__(cls, microseconds=int(value) // 1000) | ||
elif reso == NPY_DATETIMEUNIT.NPY_FR_us: | ||
td_base = _Timedelta.__new__(Timedelta, microseconds=int(value)) | ||
td_base = _Timedelta.__new__(cls, microseconds=int(value)) | ||
elif reso == NPY_DATETIMEUNIT.NPY_FR_ms: | ||
td_base = _Timedelta.__new__(Timedelta, milliseconds=0) | ||
td_base = _Timedelta.__new__(cls, milliseconds=0) | ||
elif reso == NPY_DATETIMEUNIT.NPY_FR_s: | ||
td_base = _Timedelta.__new__(Timedelta, seconds=0) | ||
td_base = _Timedelta.__new__(cls, seconds=0) | ||
# Other resolutions are disabled but could potentially be implemented here: | ||
# elif reso == NPY_DATETIMEUNIT.NPY_FR_m: | ||
# td_base = _Timedelta.__new__(Timedelta, minutes=int(value)) | ||
|
@@ -1502,7 +1502,7 @@ cdef class _Timedelta(timedelta): | |
@classmethod | ||
def _from_value_and_reso(cls, int64_t value, NPY_DATETIMEUNIT reso): | ||
# exposing as classmethod for testing | ||
return _timedelta_from_value_and_reso(value, reso) | ||
return _timedelta_from_value_and_reso(cls, value, reso) | ||
|
||
def as_unit(self, str unit, bint round_ok=True): | ||
""" | ||
|
@@ -1737,7 +1737,7 @@ class Timedelta(_Timedelta): | |
if value == NPY_NAT: | ||
return NaT | ||
|
||
return _timedelta_from_value_and_reso(value, NPY_FR_ns) | ||
return _timedelta_from_value_and_reso(cls, value, NPY_FR_ns) | ||
|
||
def __setstate__(self, state): | ||
if len(state) == 1: | ||
|
@@ -1829,6 +1829,7 @@ class Timedelta(_Timedelta): | |
return NaT | ||
|
||
return _timedelta_from_value_and_reso( | ||
Timedelta, | ||
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. should this be 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. same for other arithmetic methods above 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. I had added a question re: this but somehow github ate it, weird.. Anyway, here is my concern, if I make the change you are suggesting
Maybe that is fine, but it also kinda weirded me out, which is why I wanted to ask you. It feels a little bit like it should be the responsibility of the subclass to implement the custom Wondering: does the rest of pandas respect subclasses in this way? 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.
i dont think we're very consistent about it. IIRC the stdlib timedelta has something like:
which we could emulate. let's stick a pin in that for now and can keep 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. Should I go ahead and create an issue for this? |
||
<int64_t>(other * self.value), | ||
reso=self._creso, | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.