8000 API: positional indexing with IntegerArray · Issue #30738 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
API: positional indexing with IntegerArray #30738
Closed
@jorisvandenbossche

Description

@jorisvandenbossche

Currently, the following does not work (but probably should):

In [12]: arr1 = pd.array([1, 2, 3]) 

In [13]: arr2 = pd.array([0, 2])

In [14]: arr1[arr2]  
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-14-1646c66d4d26> in <module>
----> 1 arr1[arr2]

~/scipy/pandas/pandas/core/arrays/integer.py in __getitem__(self, item)
    375             item = check_bool_array_indexer(self, item)
    376 
--> 377         return type(self)(self._data[item], self._mask[item])
    378 
    379     def _coerce_to_ndarray(self, dtype=None, na_value=lib._no_default):

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

So that raises the following questions:

  • This should probably simply work for the above case? (converting the IntegerArray to a numpy integer array, instead of object array, so numpy's indexing works) We might want to combine this with the boolean array checking?
  • What if there are missing values? This should probably simply raise an error for now (which is what pandas 0.25 also does), although we could consider propagating an NA value as well, I think.

For Series, this seems to work partly. For iloc it works for the case without missing values. For __getitem__ you get the same error as above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignExtensionArrayExtending pandas with custom dtypes or arrays.IndexingRelated to indexing on series/frames, not to indexes themselvesMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0