Skip to content

np.searchsorted fails on Index due to Index.searchsorted not taking a sorter argument. #12238

Closed
@bsdfish

Description

@bsdfish
import numpy, pandas
ix = pandas.Float64Index([1,2,3])
numpy.searchsorted(ix, 2.5)

leads to

TypeError
..../site-packages/numpy/core/fromnumeric.pyc in searchsorted(a, v, side, sorter)
   1086     except AttributeError:
   1087         return _wrapit(a, 'searchsorted', v, side, sorter)
-> 1088     return searchsorted(v, side, sorter)

TypeError: searchsorted() takes at most 3 arguments (4 given)

The reason is that the interface of Index.searchsorted(self, key, side='left') doesn't match numpy.ndarray.searchsorted(self, v, side='left', sorter=None) and numpy.searchsorted is implemented as

def searchsorted(a, v, side='left', sorter=None):
    try:
        searchsorted = a.searchsorted
    except AttributeError:
        return _wrapit(a, 'searchsorted', v, side, sorter)
    return searchsorted(v, side, sorter)

This is pandas 0.17.1 (but the relevant code seems to appear in master) and numpy 1.10.4 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions