Skip to content

API: Make searchsorted raise TypeError on mismatched types #54668

@mroeschke

Description

@mroeschke
In [1]: import pandas as pd

In [2]: s = pd.Series([1, 2, "1"])
   ...: s.sort_values()
TypeError: '<' not supported between instances of 'str' and 'int'

In [3]: s = pd.Series([1, 2])
   ...: s.searchsorted("1")
Out[3]: 0

In [4]: import numpy as np

In [5]: arr = np.array([1, 2])

In [6]: arr.searchsorted("1")
Out[6]: 0

Looks like we are mirroring this behavior from numpy, but since Series does not support sorting incomparable objects then it seems like searchsorted with incomparable objects should raise too

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions