Skip to content

BUG: TimedeltaIndex.__rfloordiv__ triggers ZeroDivisionError when other is a list but works for scalar #54554

Open
@twoertwein

Description

@twoertwein

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd 
import datetime

index = pd.Index([pd.Timedelta(1)], dtype="timedelta64[s]")
delta = datetime.timedelta(1)

# floordiv
index // delta # works, 0 (dtype: int64)
index // [delta] # works, 0 (dtype: object!)
delta // index # works, 0 (dtype (int64))
[delta] // index # ZeroDivisionError

# truediv
index / delta # works, 0.0 (dtype: float64)
index / [delta] # works, 0.0 (dtype: object!)
delta / index # works, inf! (dtype: float64)
[delta] / index # ZeroDivisionError

Issue Description

I would expect the same behavior in the above two examples.

edit: and the dtype and the result should be the same (see object and inf)

Expected Behavior

Scalar works, but it raises with the same scalar in a list.

xref pandas-dev/pandas-stubs#764

Installed Versions

/var/home/twoertwein/.cache/pypoetry/virtualenvs/pandas-stubs-DrIM1v70-py3.11/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : 0f43794
python : 3.11.4.final.0
python-bits : 64
OS : Linux
OS-release : 6.4.7-200.fc38.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Thu Jul 27 20:01:18 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.0.1
Cython : 3.0.0
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.2
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2023.6.0
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 12.0.1
pyreadstat : 1.2.2
pyxlsb : 1.0.10
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : 2.0.19
tables : 3.8.0
tabulate : 0.9.0
xarray : 2023.1.0
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexRelated to the Index class or subclassesNumeric OperationsArithmetic, Comparison, and Logical operationsTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions