Skip to content

Conversation

@rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Dec 4, 2025

No whatsnew as this regression was introduced as part of 3.0 development.

The issue is multiplication with complex numbers and infinities can be surprising:

print(1j * float("inf"))
# (nan+infj)

The NaN comes from inf being interpreted as inf + 0j. Then (inf + 0j) * (0 + 1j) makes the real part consist of inf * 0 + 0j * 1j with inf*0 giving nan. We therefore need to avoid multiplication.

@rhshadrach rhshadrach added this to the 3.0 milestone Dec 4, 2025
@rhshadrach rhshadrach added Bug Regression Functionality that used to work in a prior pandas version Interval Interval data type labels Dec 4, 2025
comb = (np.array(left.ravel(), dtype="complex128")) + (
1j * np.array(right.ravel(), dtype="complex128")
)
comb = np.array(left.ravel(), dtype="complex128")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use np.asarray? (NumPy might copy anyways but would be nice if it didn't in this case)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, but I believe it always makes a copy when going float64 -> complex128. I also tried

comb = np.empty(left.shape, dtype="complex128")
comb.real = left
comb.imag = right

but that had slightly worse performance than the identical np.array and np.asarray.

@mroeschke mroeschke merged commit 03c3239 into pandas-dev:main Dec 5, 2025
41 checks passed
@mroeschke
Copy link
Member

Thanks @rhshadrach

@khemkaran10
Copy link
Contributor

Thanks @rhshadrach.

@rhshadrach rhshadrach deleted the regr_interval_inf branch December 5, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Interval Interval data type Regression Functionality that used to work in a prior pandas version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Inconsisten nunique behavior with Intervals on latest nightly

3 participants