Skip to content

[pandas] Fix pandas Timedelta total_seconds return type #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

sjdemartini
Copy link
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 gramster merged commit c2b5349 into microsoft:main Feb 23, 2022
@sjdemartini sjdemartini deleted the patch-1 branch February 23, 2022 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants