Code Sample, a copy-pastable example if possible
>>> import pandas as pd
>>> pd.__version__
'1.1.0.dev0+288.gac61a8a62'
>>> pd.core.arrays.IntervalArray.from_breaks([1, 2, 3, 4]) == (i for i in range(10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\simon\pandas\pandas\core\arrays\interval.py", line 562, in __eq__
if len(self) != len(other):
TypeError: object of type 'generator' has no len()
>>>
Problem description
Raises TypeError
mypy gives pandas\core\arrays\interval.py:563: error: Argument 1 to "len" has incompatible type "object"; expected "Sized"
similar problem with IntegerArray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\simon\pandas\pandas\core\ops\common.py", line 64, in new_method
return method(self, other)
File "C:\Users\simon\pandas\pandas\core\arrays\integer.py", line 531, in cmp_method
if len(self) != len(other):
TypeError: len() of unsized object
>>>
and other Extension Arrays.
Expected Output
Not to raise TypeError
I think returning
<BooleanArray>
[False, False, False]
Length: 3, dtype: boolean
would be consistent with numpy array
>>> import numpy as np
>>> np.array([1, 2, 3]) == (i for i in range(10))
array([False, False, False])
and Series
>>> pd.Series([1, 2, 3]) == (i for i in range(10))
0 False
1 False
2 False
dtype: bool
>>>
Output of pd.show_versions()
[paste the output of ``pd.show_versions()`` here below this line]
Comment From: jorisvandenbossche
I am personally not sure we should return a boolean array if the "length" doesn't match
Comment From: jbrockmendel
im with joris on this one. id expect this to behave like self == list(other)
(or just refuse to operate and raise)
Comment From: simonjayhawkins
an iterator doesn't have a length. we just take values.
imo array-likes should behave consistently, so EA should behave like np.ndarray and pd.Series.