Skip to content

Timedelta interpreted as int upon first insertion into Series #22717

Closed
@kernc

Description

@kernc

Code Sample, a copy-pastable example if possible

>>> s = pd.Series(['x'])
>>> s['td'] = pd.Timedelta('9 days')
>>> s
0                   x
td    777600000000000
dtype: object

# However, *if the key already exists*, it works as expected:
>>> s['td_2'] = 0
>>> s['td_2'] = pd.Timedelta('9 days')
>>> s
0                    x
td     777600000000000
td_2   9 days 00:00:00
dtype: object

Problem description

Timedeltas should remain Timedeltas when inserted into object Series, particularly because they are nice to work with. 😅

Expected Output

>>> s = pd.Series(['x'])
>>> s['td'] = pd.Timedelta('9 days')
>>> s
0                    x
td     9 days 00:00:00
dtype: object

Output of pd.show_versions()

pandas 0.23.3

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