Open
Description
Broken off of #17117 for discussion, xref #8162, #17061, recent mailing list thread.
With a datetime-like column we can access year, hour, ... with self.dt.foo
. With a DatetimeIndex (PeriodIndex, ...) we access these attributes directly self.foo
without the .dt
. I'd like to add a .dt
property to the appropriate Index subclasses so that these attributes can be accessed symmetrically. i.e. instead of:
if isinstance(obj, pd.Index):
year = obj.year
elif isinstance(obj, pd.Series):
year = obj.dt.year
we can just use year = obj.dt.year
regardless.
The implementation is three lines in core.indexes.datetimelike.DatetimeIndexOpsMixin`:
@property
def dt(self):
return self
Thoughts?