pandas timedelta with float argument

Viewed 58

pandas Timedelta documentation states that the value input parameter should be of the following types:

valueTimedelta, timedelta, np.timedelta64, str, or int

However, when I use a floating point number for value, it seems to work fine. For example:

pd.Timedelta(1.234234, "h")

yields

Timedelta('0 days 01:14:03.242400')

This functionality is said to be based on numpy's timedelta64 which indeed raises an error when passed a floating point argument.

So, is it always safe to use a floating point number for value with pandas Timedelta? Is the docstring simply wrong?

1 Answers

It's interesting to note that:

pd.Timedelta(1.234234, "h")

Is equivalent to:

pd.Timedelta(hours=1.234234)

And later on in the documentation it states:

**kwargs ... Values for construction in compat with datetime.timedelta. ... python ints and floats.

So, I believe it should always be safe to use floating point numbers, and that the docstring is probably outdated.

Related