TypeError: searchsorted requires compatible dtype or scalar, not Series · Issue #32762 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

x = ['1998-01-07 13:17:00', '1998-01-07 13🔞00', '1998-01-07 13:19:00', '1998-01-07 13:20:00',
     '1998-01-07 13:21:00', '1998-01-07 13:22:00', '1998-01-07 13:23:00', '1998-01-07 13:24:00',
     '1998-01-07 13:25:00', '1998-01-07 13:26:00']
df = pd.DataFrame(x)
df.set_index(df.iloc[:, 0], inplace=True)
df.index = pd.DatetimeIndex(df.index.values)

Problem description

I want to apply searchsorted function to df index:
df.index.searchsorted(pd.Series(np.array([df.index[0], df.index.max()])))
but it returns an error:

TypeError: searchsorted requires compatible dtype or scalar, not Series

Why it doesn't find the nearest datetimeindex in time? I think this works with older versions of pandas.

I use the lastest version of pandas (1.0.3.)