Skip to content

BUG/API: to_timedelta unit-argument ignored for string input #12136

Closed
@belteshassar

Description

@belteshassar

So, I don't know if this is by design, but it sure confused me. to_timedelta() operates differently on the number 1000 compared to the string '1000':

In[3]: pd.to_timedelta(1000, unit='ms')
Out[3]: Timedelta('0 days 00:00:01')
In[4]: pd.to_timedelta(1000.0, unit='ms')
Out[4]: Timedelta('0 days 00:00:01')

and

In[6]: pd.to_timedelta('1000ms')
Out[6]: Timedelta('0 days 00:00:01')

while

In[5]: pd.to_timedelta('1000', unit='ms')
Out[5]: Timedelta('0 days 00:00:00.000001')

I've tried my best to come up with a reason for why this behaviour would be desirable, but I can't think of any.

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