Skip to content

CLN: indexing Exception in Series #28588

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

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,9 @@ def _get_with(self, key):
elif isinstance(key, tuple):
try:
return self._get_values_tuple(key)
except Exception:
except ValueError:
# if we don't have a MultiIndex, we may still be able to handle
# a 1-tuple. see test_1tuple_without_multiindex
if len(key) == 1:
key = key[0]
if isinstance(key, slice):
Expand Down Expand Up @@ -1186,7 +1188,9 @@ def _get_values(self, indexer):
return self._constructor(
self._data.get_slice(indexer), fastpath=True
).__finalize__(self)
except Exception:
except ValueError:
# mpl compat if we look up e.g. ser[:, np.newaxis];
# see tests.series.timeseries.test_mpl_compat_hack
return self._values[indexer]

def _get_value(self, label, takeable: bool = False):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,3 +1202,12 @@ def test_readonly_indices():
result = df["data"].iloc[indices]
expected = df["data"].loc[[1, 3, 6]]
tm.assert_series_equal(result, expected)


def test_1tuple_without_multiindex():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works already on master right? So not a behavior change just additional coverage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This adds coverage for the case where the exception on L1134 is reached

ser = pd.Series(range(5))
key = (slice(3),)

result = ser[key]
expected = ser[key[0]]
tm.assert_series_equal(result, expected)