File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -1131,7 +1131,9 @@ def _get_with(self, key):
11311131 elif isinstance (key , tuple ):
11321132 try :
11331133 return self ._get_values_tuple (key )
1134- except Exception :
1134+ except ValueError :
1135+ # if we don't have a MultiIndex, we may still be able to handle
1136+ # a 1-tuple. see test_1tuple_without_multiindex
11351137 if len (key ) == 1 :
11361138 key = key [0 ]
11371139 if isinstance (key , slice ):
@@ -1186,7 +1188,9 @@ def _get_values(self, indexer):
11861188 return self ._constructor (
11871189 self ._data .get_slice (indexer ), fastpath = True
11881190 ).__finalize__ (self )
1189- except Exception :
1191+ except ValueError :
1192+ # mpl compat if we look up e.g. ser[:, np.newaxis];
1193+ # see tests.series.timeseries.test_mpl_compat_hack
11901194 return self ._values [indexer ]
11911195
11921196 def _get_value (self , label , takeable : bool = False ):
Original file line number Diff line number Diff line change @@ -1202,3 +1202,12 @@ def test_readonly_indices():
12021202 result = df ["data" ].iloc [indices ]
12031203 expected = df ["data" ].loc [[1 , 3 , 6 ]]
12041204 tm .assert_series_equal (result , expected )
1205+
1206+
1207+ def test_1tuple_without_multiindex ():
1208+ ser = pd .Series (range (5 ))
1209+ key = (slice (3 ),)
1210+
1211+ result = ser [key ]
1212+ expected = ser [key [0 ]]
1213+ tm .assert_series_equal (result , expected )
You can’t perform that action at this time.
0 commit comments