BUG(?) Index.__getitem__ with 0D numpy array raises AssertionError (original) (raw)

In [5]: pd.Index([2, 2, 2])[np.array(0)]

AssertionError Traceback (most recent call last) Cell In[5], line 1 ----> 1 pd.Index([2, 2, 2])[np.array(0)]

File ~/pandas/core/indexes/base.py:5370, in Index.getitem(self, key) 5366 disallow_ndim_indexing(result) 5368 # NB: Using _constructor._simple_new would break if MultiIndex 5369 # didn't override getitem -> 5370 return self._constructor._simple_new(result, name=self._name)

File ~/pandas/core/indexes/base.py:641, in Index._simple_new(cls, values, name, refs) 631 @classmethod 632 def _simple_new( 633 cls, values: ArrayLike, name: Hashable | None = None, refs=None 634 ) -> Self: 635 """ 636 We require that we have a dtype compat for the values. If we are passed 637 a non-dtype compat, then coerce using the constructor. 638 639 Must be careful not to recurse. 640 """ --> 641 assert isinstance(values, cls._data_cls), type(values) 643 result = object.new(cls) 644 result._data = values

AssertionError: <class 'numpy.int64'>

Not sure if we should allow this case, but I would expect either 2 or a ValueError