Open
Description
# based on test_constructor_ndarray_like
class ArrayLike:
def __init__(self, array) -> None:
self.array = array
# __array__ but no __iter__, so is_list_like(obj) is False
def __array__(self, dtype=None) -> np.ndarray:
return self.array
obj = ArrayLike(np.arange(5))
result = pd.Index(obj) # <- unpacks array
result2 = pd.Series(obj) # <- treats obj as a scalar
result3 = pd.array(obj) # <- raises "TypeError: 'ArrayLike' object is not iterable"
We should aim for consistent behavior between these three constructors. I lean towards preferring the raising behavior here, but could be convinced otherwise as long as we move towards consistency.