A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/9467 below:

SparseSeries __getitem__ uses questionable, buggy logic · Issue #9467 · pandas-dev/pandas · GitHub

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:
https://github.com/pydata/pandas/blob/bb9c311f36fbf508d11f2eabe3fdbdd010abf8c0/pandas/sparse/series.py#L361

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!')
    372
    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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4