-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Closed
Labels
ComplexComplex NumbersComplex NumbersNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressionsNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operationsgood first issue
Description
TL;DR: our comparisons with complex dtypes are not internally consistent:
arr = np.arange(5).astype(np.complex128)
ser = pd.Series(arr)
df = ser.to_frame()
>>> df < df.astype(object)
[...]
TypeError: '<' not supported between instances of 'complex' and 'complex'
>>> df.lt(df.astype(object))
0
0 False
1 False
2 False
3 False
4 False
Digging into this...
numpy has some surprising behavior for comparing complex dtypes:
arr = np.arange(5)
arr = arr + arr*1j
arr2 = arr*2 - 1
>>> arr < arr2
array([False, True, True, True, True])
I would expect these inequalities to be undefined, and in fact, if we cast to object we get a TypeError:
>>> arr < arr2.astype(object)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'complex' and 'complex'
That's the behavior I expected in the first place, but then trying it on just the scalars:
>>> arr[0] < arr2[0]
False
Metadata
Metadata
Assignees
Labels
ComplexComplex NumbersComplex NumbersNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressionsNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operationsgood first issue