Skip to content

[pandas] Fix pandas Timedelta total_seconds return type - #169

Merged
Graham Wheeler (gramster) merged 1 commit into
microsoft:mainfrom
sjdemartini:patch-1
Feb 23, 2022
Merged

Graham Wheeler (gramster) merged 1 commit into
microsoft:mainfrom
sjdemartini:patch-1

Conversation

@sjdemartini

Copy link
Copy Markdown
Contributor

The total_seconds method returns a float, rather than an int. I noticed this problem seeing incorrect typing within VSCode.

The correct return type can be tested/confirmed as follows:

import pandas as pd
ptd = pd.to_timedelta(1234.5678, unit="s")
print(ptd.total_seconds())  # 1234.5678
print(type(ptd.total_seconds()))  # <class 'float'>
print(type(ptd))  # <class 'pandas._libs.tslibs.timedeltas.Timedelta'>

And similarly in the types within the pandas repo https://github.com/pandas-dev/pandas/blob/7f97e27241dc520038d8d1b0de114afec3ad24df/pandas/_libs/tslibs/timedeltas.pyi#L50

The `total_seconds` method returns a float, rather than an int.

This can be tested/confirmed as follows:

```python
import pandas as pd
ptd = pd.to_timedelta(1234.5678, unit="s")
print(ptd.total_seconds())  # 1234.5678
print(type(ptd.total_seconds()))  # <class 'float'>
print(type(ptd))  # <class 'pandas._libs.tslibs.timedeltas.Timedelta'>
```
@gramster
Graham Wheeler (gramster) merged commit c2b5349 into microsoft:main Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants