Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: positional indexing with IntegerArray #30738

Closed
jorisvandenbossche opened this issue Jan 6, 2020 · 0 comments · Fixed by #31150
Closed

API: positional indexing with IntegerArray #30738

jorisvandenbossche opened this issue Jan 6, 2020 · 0 comments · Fixed by #31150
Labels
API Design ExtensionArray Extending pandas with custom dtypes or arrays. Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jorisvandenbossche
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design ExtensionArray Extending pandas with custom dtypes or arrays. Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
1 participant