KrishnaswamyLab / scprep

A collection of scripts and tools for loading, processing, and handling single cell data.
MIT License
72 stars 19 forks source link

`scprep.select.select_*` is ambiguous with modified RangeIndex #83

Open scottgigante opened 5 years ago

scottgigante commented 5 years ago

The attempt to disambiguate between loc and iloc with pandas objects fails when the index is integer-valued.

>>> import scprep
>>> import pandas as pd
>>> X = pd.DataFrame([[0], [1], [2], [3], [4]])
>>> Y = X.iloc[[0, 2, 3]]
>>> scprep.select.select_rows(Y, idx=[0, 1])
/home/scottgigante/.local/lib/python3.7/site-packages/scprep/select.py:466: FutureWarning:
Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.

See the documentation here:
https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike
  data = data.loc[idx]
     0
0  0.0
1  NaN

Desired output would be to treat [0,1] as an attempt to iloc.

Worse still is the case when indices are not missing, but out of order. What is the desired output of the following? An ambiguity warning, probably.

>>> Y = X.iloc[[0, 2, 1, 3]]
>>> Y
   0
0  0
2  2
1  1
3  3
>>> scprep.select.select_rows(Y, idx=[0,1])
   0
0  0
1  1