Skip to content

API: .dt.components attribute on timedelta series does not preserve the index #9247

Closed
@jorisvandenbossche

Description

@jorisvandenbossche
In [70]: tds = pd.Series(pd.timedelta_range('1 days', periods=5, freq='2 h'), index=list('ABCDE'))

In [71]: tds
Out[71]:
A   1 days 00:00:00
B   1 days 02:00:00
C   1 days 04:00:00
D   1 days 06:00:00
E   1 days 08:00:00
dtype: timedelta64[ns]

In [72]: tds.dt.hours
Out[72]:
A    0
B    2
C    4
D    6
E    8
dtype: int64

In [73]: tds.dt.components.hours
Out[73]:
0    0
1    2
2    4
3    6
4    8
Name: hours, dtype: int64

So the direct attributes via .dt like .dt.hours above does preserve the index, but the components not.

@jreback I don't know if this was done on purpose or is an oversight, I can't remember, and I looked briefly to the long discussion in #8184, but didn't find something directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions