Skip to content

IntervalArray equality with wrong length Iterable raises TypeError #31646

Open
@simonjayhawkins

Description

@simonjayhawkins

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugExtensionArrayExtending pandas with custom dtypes or arrays.IntervalInterval data typeNeeds DiscussionRequires discussion from core team before further actionNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions