@@ -1222,10 +1222,7 @@ def slice_locs(self, start=None, end=None):
1222
1222
1223
1223
is_unique = self .is_unique
1224
1224
if start is None :
1225
- if is_unique :
1226
- start_slice = 0
1227
- else :
1228
- start_slice = np .arange (len (self ))
1225
+ start_slice = 0
1229
1226
else :
1230
1227
try :
1231
1228
start_slice = self .get_loc (start )
@@ -1235,21 +1232,10 @@ def slice_locs(self, start=None, end=None):
1235
1232
# get_loc will return a boolean array for non_uniques
1236
1233
# if we are not monotonic
1237
1234
if isinstance (start_slice ,np .ndarray ):
1238
- if not self .is_monotonic :
1239
- raise KeyError ("cannot peform a slice operation "
1240
- "on a non-unique non-monotonic index" )
1241
- start_slice = np .arange (len (self ))[start_slice ]
1242
-
1243
- # select all in the slice + all the rest of the entries
1244
- # to the right
1245
- elif isinstance (start_slice , slice ):
1246
- ss = np .arange (start_slice .stop ,len (self ))
1247
- start_slice = np .arange (len (self ))[start_slice ]
1248
- start_slice = (Index (ss ) | Index (start_slice )).values
1249
- else :
1250
- start_slice = np .arange (start_slice ,len (self ))
1235
+ raise KeyError ("cannot peform a slice operation "
1236
+ "on a non-unique non-monotonic index" )
1251
1237
1252
- elif isinstance (start_slice , slice ):
1238
+ if isinstance (start_slice , slice ):
1253
1239
start_slice = start_slice .start
1254
1240
1255
1241
except KeyError :
@@ -1259,10 +1245,7 @@ def slice_locs(self, start=None, end=None):
1259
1245
raise
1260
1246
1261
1247
if end is None :
1262
- if is_unique :
1263
- end_slice = len (self )
1264
- else :
1265
- end_slice = np .arange (len (self ))
1248
+ end_slice = len (self )
1266
1249
else :
1267
1250
try :
1268
1251
end_slice = self .get_loc (end )
@@ -1271,20 +1254,10 @@ def slice_locs(self, start=None, end=None):
1271
1254
1272
1255
# get_loc will return a boolean array for non_uniques
1273
1256
if isinstance (end_slice ,np .ndarray ):
1274
- if not self .is_monotonic :
1275
- raise KeyError ("cannot perform a slice operation "
1276
- "on a non-unique non-monotonic index" )
1277
- end_slice = np .arange (len (self ))[end_slice ]
1278
-
1279
- # select all in the slice + all to the left of the entries
1280
- elif isinstance (end_slice , slice ):
1281
- es = np .arange (0 ,end_slice .start )
1282
- end_slice = np .arange (len (self ))[end_slice ]
1283
- end_slice = (Index (es ) | Index (end_slice )).values
1284
- else :
1285
- end_slice = np .arange (0 ,end_slice + 1 )
1257
+ raise KeyError ("cannot perform a slice operation "
1258
+ "on a non-unique non-monotonic index" )
1286
1259
1287
- elif isinstance (end_slice , slice ):
1260
+ if isinstance (end_slice , slice ):
1288
1261
end_slice = end_slice .stop
1289
1262
else :
1290
1263
end_slice += 1
@@ -1295,16 +1268,6 @@ def slice_locs(self, start=None, end=None):
1295
1268
else :
1296
1269
raise
1297
1270
1298
- if not is_unique :
1299
- # see if we can convert back to and edge slice
1300
- if len (start_slice ) == len (end_slice ) and (start_slice == end_slice ).all ():
1301
- start_slice , end_slice = start_slice [0 ], start_slice [- 1 ]+ 1
1302
- # partial slice
1303
- elif (len (start_slice ) == start_slice [- 1 ]- start_slice [0 ]+ 1 ) and (
1304
- len (end_slice ) == end_slice [- 1 ]- end_slice [0 ]+ 1 ):
1305
- res = (Index (start_slice ) & Index (end_slice )).values
1306
- start_slice , end_slice = res [0 ],res [- 1 ]+ 1
1307
-
1308
1271
return start_slice , end_slice
1309
1272
1310
1273
def delete (self , loc ):
0 commit comments