Skip to content

Behaviour change in 1.5.0 when using Timedelta as Enum data type #48908

@maread99

Description

@maread99

From 1.5.0 it appears that pd.Timedelta behavior has changed when used as an Enum data-type...

Before:

>>> import pandas as pd >>> pd.__version__ '1.4.3' >>> from enum import Enum >>> class TDEnum(pd.Timedelta, Enum): ... T1 = 60000000000 ... ... def plus_one_hour(self): ... return self + pd.Timedelta(hours=1) ... >>> TDEnum["T1"] # as is usual when defining a data-type, returns enum... <TDEnum.T1: Timedelta('0 days 00:01:00')> >>> # ...such that methods defined on the enum are available... >>> TDEnum["T1"].plus_one_hour() Timedelta('0 days 01:01:00') 

1.5.0:

>>> import pandas as pd >>> pd.__version__ '1.5.0' >>> # class defined as before... >>> from enum import Enum >>> class TDEnum(pd.Timedelta, Enum): ... T1 = 60000000000 ... ... def plus_one_hour(self): ... return self + pd.Timedelta(hours=1) ... >>> TDEnum["T1"] # now returns the pd.Timedelta enum value Timedelta('0 days 00:01:00') >>> # i.e. methods defined on the enum are no longer available >>> TDEnum["T1"].plus_one_hour() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Timedelta' object has no attribute 'plus_one_hour' 

I was reluctant to report this as a bug, although it is true that the Timedelta class appears to no longer behave as would be expected in this case (the usual behavior when defining a data-type (including datetime.timedelta) is as the 1.4.3 behavior described above).

If this is considered a bug, any chance it can be fixed?

If it's not a bug, might you have any ideas as to how I could replicate the previous behavior?

Thank you!

Metadata

Metadata

Assignees

Labels

RegressionFunctionality that used to work in a prior pandas versionTimedeltaTimedelta data type

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions