Skip to content
Prev Previous commit
Next Next commit
Reverted downstream changes, new error message
  • Loading branch information
rhshadrach committed Sep 7, 2020
commit ba36e40dc9341d253e2461299ec1785fa2f3fe27
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Fixed regressions
- Fixed regression in :meth:`DataFrameGroupBy.agg` where a ``ValueError: buffer source array is read-only`` would be raised when the underlying array is read-only (:issue:`36014`)
- Fixed regression in :meth:`Series.__getitem__` incorrectly raising when the input was a tuple. (:issue:`35534`)
- Fixed regression in :meth:`Series.__getitem__` incorrectly raising when the input was a frozenset. (:issue:`35747`)
-

.. ---------------------------------------------------------------------------

Expand Down
8 changes: 5 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def _get_with(self, key):
"Indexing a Series with DataFrame is not "
"supported, use the appropriate DataFrame column"
)
elif isinstance(key, tuple) and isinstance(self.index, MultiIndex):
elif isinstance(key, tuple):
return self._get_values_tuple(key)

elif not is_list_like(key):
Expand Down Expand Up @@ -958,7 +958,7 @@ def _get_values_tuple(self, key):
return result

if not isinstance(self.index, MultiIndex):
raise ValueError("Can only tuple-index with a MultiIndex")
raise ValueError("key of type tuple not found and not a MultiIndex")

# If key is contained, would have returned by now
indexer, new_index = self.index.get_loc_level(key)
Expand Down Expand Up @@ -1014,7 +1014,9 @@ def __setitem__(self, key, value):

except TypeError as e:
if isinstance(key, tuple) and not isinstance(self.index, MultiIndex):
raise ValueError("Can only tuple-index with a MultiIndex") from e
raise ValueError(
"key of type tuple not found and not a MultiIndex"
) from e

if com.is_bool_indexer(key):
key = check_bool_indexer(self.index, key)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def test_2d_to_1d_assignment_raises():
@pytest.mark.filterwarnings("ignore:Using a non-tuple:FutureWarning")
def test_basic_getitem_setitem_corner(datetime_series):
# invalid tuples, e.g. td.ts[:, None] vs. td.ts[:, 2]
msg = "Can only tuple-index with a MultiIndex"
msg = "key of type tuple not found and not a MultiIndex"
with pytest.raises(ValueError, match=msg):
datetime_series[:, 2]
with pytest.raises(ValueError, match=msg):
Expand Down