-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
pls add tests where appropriate |
done |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
should this be type(self)
?
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.
same for other arithmetic methods above
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.
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
td1 = MyTimedeltaSubclass("10 minutes")
td2 = Timedelta ("10 minutes")
then result types will be inconsistent
td1 + td2 -> MyTimedeltaSubclass
td2 + td1 -> Timedelta
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 __add__
behaviour.
Wondering: does the rest of pandas respect subclasses in this way?
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.
does the rest of pandas respect subclasses in this way?
i dont think we're very consistent about it. IIRC the stdlib timedelta has something like:
def __add__(self, other):
if self_is_timedelta and other_is_timedelta_subclass:
return NotImplemented
[...]
which we could emulate. let's stick a pin in that for now and can keep Timedelta
like you currently have
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.
Should I go ahead and create an issue for this?
Can you add a note in the 1.5.2 file |
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.
Looks reasonable. @jbrockmendel merge when ready
thanks @krasch |
Oops, something went wrong applying the patch ... Please have a look at my logs. |
…pandas-dev#49579) * Add cls argument to _timedelta_from_value_and_reso * Add test * Add fix to changelog Co-authored-by: krasch <dev@krasch.io> (cherry picked from commit 606499d) # Conflicts: # pandas/_libs/tslibs/timedeltas.pyx # pandas/tests/scalar/timedelta/test_constructors.py
…pandas-dev#49579) * Add cls argument to _timedelta_from_value_and_reso * Add test * Add fix to changelog Co-authored-by: krasch <dev@krasch.io>
Timedelta
asEnum
data type #48908doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.