Skip to content

BUG: Inconsisten nunique behavior with Intervals on latest nightly #63218

@cbourjau

Description

@cbourjau

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 numpy as np

print(f"{pd.__version__}")

# inf in left position
s = pd.Series([pd.Interval(-np.inf, 0), pd.Interval(-np.inf, 1)])
assert s.nunique() == 2
assert len(s.drop_duplicates()) == 2

# inf in right position
s = pd.Series([pd.Interval(0, np.inf), pd.Interval(1, np.inf)])
assert len(s.drop_duplicates()) == 2
assert s.nunique() == 2  # Fails on latest nightly ( == 0)

Issue Description

The semantics of nunique appear to have changed on the latest nightly version as demonstrated by the above example which passes on pandas 2.3.3 but fails on the latest nightly. Intervals with inf values on the right seem to be treated as nan values. Using -inf for the left-hand side of an interval works as it used to.

Notably, the nightly version raises the following suspicious warning:

[...]/pandas-debug/.pixi/envs/nightly/lib/python3.14/site-packages/pandas/core/arrays/interval.py:2132: RuntimeWarning: invalid value encountered in multiply
  1j * np.array(right.ravel(), dtype="complex128")

Expected Behavior

I'd expect the semantics of nunique to be unchanged

Installed Versions

INSTALLED VERSIONS

commit : a885d67
python : 3.14.0
python-bits : 64
OS : Darwin
OS-release : 24.6.0
Version : Darwin Kernel Version 24.6.0: Mon Aug 11 21:15:09 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6041
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 3.0.0.dev0+2752.ga885d67965
numpy : 2.3.5
dateutil : 2.9.0.post0
pip : 25.3
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions