New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bsdfish opened this Issue Feb 5, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@bsdfish

bsdfish commented Feb 5, 2016

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 .

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Feb 10, 2016

Contributor

I suppose it should take the sorter arg. PR's welcome.

note that this works.

In [3]: ix.searchsorted(2.5)
Out[3]: 2
Contributor

jreback commented Feb 10, 2016

I suppose it should take the sorter arg. PR's welcome.

note that this works.

In [3]: ix.searchsorted(2.5)
Out[3]: 2

@jreback jreback added this to the Next Major Release milestone Feb 10, 2016

@jreback jreback modified the milestones: 0.18.0, Next Major Release Feb 23, 2016

@jreback jreback modified the milestones: 0.18.1, 0.18.0 Feb 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment