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

BUG/CLN: SparseSeries __getitem__ uses questionable, buggy logic #9467

shoyer opened this Issue Feb 11, 2015 · 0 comments


None yet
2 participants

shoyer commented Feb 11, 2015

SparseSeries currently relies on the assumption that all non-scalar input will raise a TypeError (because it won't be hashable) when used as input to Index.get_loc:

However, some non-scalar input is hashable (e.g., Ellipsis):

In [2]: import pandas as pd

In [3]: ss = pd.Series(range(10)).to_sparse()

In [4]: ss[...]
Exception                                 Traceback (most recent call last)
<ipython-input-4-f0ccf654123b> in <module>()
----> 1 ss[...]

/Users/shoyer/dev/pandas/pandas/sparse/series.pyc in __getitem__(self, key)
    369             if isinstance(key, (int, np.integer)):
    370                 return self._get_val_at(key)
--> 371             raise Exception('Requested index not in this series!')
    373         except TypeError:

Exception: Requested index not in this series!

(this should return the entire sparse series)

This logic is also problematic because it relies on get_loc always throwing TypeError for invalid input. So this could use some cleanup, ideally checking directly if the input is hashable. And it probably shouldn't be raising a generic Exception, either.

xref tslib.pyx change/discussion in #9258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment