@@ -1373,6 +1373,62 @@ def dot(self, other):
1373
1373
else : # pragma: no cover
1374
1374
raise TypeError ('unsupported type: %s' % type (other ))
1375
1375
1376
+ def searchsorted (self , v , side = 'left' , sorter = None ):
1377
+ """Find indices where elements should be inserted to maintain order.
1378
+
1379
+ Find the indices into a sorted Series `self` such that, if the
1380
+ corresponding elements in `v` were inserted before the indices, the
1381
+ order of `self` would be preserved.
1382
+
1383
+ Parameters
1384
+ ----------
1385
+ v : array_like
1386
+ Values to insert into `a`.
1387
+ side : {'left', 'right'}, optional
1388
+ If 'left', the index of the first suitable location found is given.
1389
+ If 'right', return the last such index. If there is no suitable
1390
+ index, return either 0 or N (where N is the length of `a`).
1391
+ sorter : 1-D array_like, optional
1392
+ Optional array of integer indices that sort `self` into ascending
1393
+ order. They are typically the result of ``np.argsort``.
1394
+
1395
+ Returns
1396
+ -------
1397
+ indices : array of ints
1398
+ Array of insertion points with the same shape as `v`.
1399
+
1400
+ See Also
1401
+ --------
1402
+ Series.sort
1403
+ Series.order
1404
+ numpy.searchsorted
1405
+
1406
+ Notes
1407
+ -----
1408
+ Binary search is used to find the required insertion points.
1409
+
1410
+ Examples
1411
+ --------
1412
+ >>> x = pd.Series([1, 2, 3])
1413
+ >>> x
1414
+ 0 1
1415
+ 1 2
1416
+ 2 3
1417
+ dtype: int64
1418
+ >>> x.searchsorted(4)
1419
+ array([3])
1420
+ >>> x.searchsorted([0, 4])
1421
+ array([0, 3])
1422
+ >>> x.searchsorted([1, 3], side='left')
1423
+ array([0, 2])
1424
+ >>> x.searchsorted([1, 3], side='right')
1425
+ array([1, 3])
1426
+ >>> x.searchsorted([1, 2], side='right', sorter=[0, 2, 1])
1427
+ array([1, 3])
1428
+ """
1429
+ return self .values .searchsorted (Series (v ).values , side = side ,
1430
+ sorter = sorter )
1431
+
1376
1432
#------------------------------------------------------------------------------
1377
1433
# Combination
1378
1434
0 commit comments