Skip to content

Index * Series returns Index #19042

Closed
@jbrockmendel

Description

@jbrockmendel

Opening mainly so I have something to reference in the upcoming PR.

tdi = pd.TimedeltaIndex(['0days', '1day', '2days', '3days', '4days'])
ser = Series([0, 1, 2, 3, 4], dtype=np.int64)
expected = Series(['0days', '1day', '4days', '9days', '16days'],
                          dtype='timedelta64[ns]')

result = tdi * ser
tm.assert_series_equal(result, expected)   # --> fails

>>> result
TimedeltaIndex(['0 days', '1 days', '4 days', '9 days', '16 days'], dtype='timedelta64[ns]', freq=None)

Same for division:

tdi = pd.TimedeltaIndex(['0days', '1day', '2days', '3days', '4days'])
ser = Series([1.5, 3, 4.5, 6, 7.5], dtype=np.float64)
expected = Series([tdi[n] / ser[n] for n in range(len(ser))], dtype='timedelta64[ns]')

result = tdi / ser
>>> result
TimedeltaIndex(['00:00:00', '08:00:00', '10:40:00', '12:00:00', '12:48:00'], dtype='timedelta64[ns]', freq=None)

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