File tree 2 files changed +15
-2
lines changed
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):
1131
1131
elif isinstance (key , tuple ):
1132
1132
try :
1133
1133
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
1135
1137
if len (key ) == 1 :
1136
1138
key = key [0 ]
1137
1139
if isinstance (key , slice ):
@@ -1186,7 +1188,9 @@ def _get_values(self, indexer):
1186
1188
return self ._constructor (
1187
1189
self ._data .get_slice (indexer ), fastpath = True
1188
1190
).__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
1190
1194
return self ._values [indexer ]
1191
1195
1192
1196
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():
1202
1202
result = df ["data" ].iloc [indices ]
1203
1203
expected = df ["data" ].loc [[1 , 3 , 6 ]]
1204
1204
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