Skip to content
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

BUG: ValueError during floordiv of a series with timedelta type #35529

Closed
2 of 3 tasks
galipremsagar opened this issue Aug 3, 2020 · 0 comments · Fixed by #35583
Closed
2 of 3 tasks

BUG: ValueError during floordiv of a series with timedelta type #35529

galipremsagar opened this issue Aug 3, 2020 · 0 comments · Fixed by #35583
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Milestone

Comments

@galipremsagar
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

>>> import pandas as pd
>>> sr = pd.Series([10, 20, 30], dtype='timedelta64[ns]')
>>> sr
0   00:00:00.000000
1   00:00:00.000000
2   00:00:00.000000
dtype: timedelta64[ns]
>>> sr = pd.Series([1000, 20, 30], dtype='timedelta64[ns]')
>>> sr
0   00:00:00.000001
1   00:00:00.000000
2   00:00:00.000000
dtype: timedelta64[ns]
>>> sr = pd.Series([1000, 222330, 30], dtype='timedelta64[ns]')
>>> sr
0   00:00:00.000001
1   00:00:00.000222
2   00:00:00.000000
dtype: timedelta64[ns]
>>> sr1 = pd.Series([1000, 222330, None], dtype='timedelta64[ns]')
>>> sr1
0   00:00:00.000001
1   00:00:00.000222
2               NaT
dtype: timedelta64[ns]
>>> sr / sr1
0    1.0
1    1.0
2    NaN
dtype: float64
>>> sr // sr1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nvme/0/pgali/envs/cudfdev1/lib/python3.7/site-packages/pandas/core/ops/common.py", line 64, in new_method
    return method(self, other)
  File "/nvme/0/pgali/envs/cudfdev1/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 503, in wrapper
    result = arithmetic_op(lvalues, rvalues, op, str_rep)
  File "/nvme/0/pgali/envs/cudfdev1/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 193, in arithmetic_op
    res_values = dispatch_to_extension_op(op, lvalues, rvalues)
  File "/nvme/0/pgali/envs/cudfdev1/lib/python3.7/site-packages/pandas/core/ops/dispatch.py", line 125, in dispatch_to_extension_op
    res_values = op(left, right)
  File "/nvme/0/pgali/envs/cudfdev1/lib/python3.7/site-packages/pandas/core/arrays/timedeltas.py", line 637, in __floordiv__
    result[mask] = np.nan
ValueError: cannot convert float NaN to integer

Problem description

When there is a NaT in either of the series, the result should ideally be of type nullable integer (Int64) to avoid this kind of ValueError

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-76-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0.post20200704
Cython : 0.29.21
pytest : 5.4.3
hypothesis : 5.19.0
sphinx : 3.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : 0.50.1

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 3, 2020
@jbrockmendel jbrockmendel added Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type labels Aug 4, 2020
@simonjayhawkins simonjayhawkins removed the Needs Triage Issue that has not been reviewed by a pandas team member label Aug 6, 2020
@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Aug 6, 2020
wence- added a commit to wence-/cudf that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants