Skip to content

BUG: Series.searchsorted raises TypeError for incompatible value dtypes#65015

Draft
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-searchsorted
Draft

BUG: Series.searchsorted raises TypeError for incompatible value dtypes#65015
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-searchsorted

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • Series[numeric].searchsorted with incompatible value types (e.g. timedelta64, datetime64, str, Timestamp, Timedelta, Period, NaT) previously returned silently wrong results or raised confusing internal numpy errors.
  • Added validate_searchsorted_value in algorithms.py and call it from four code paths: algorithms.searchsorted (numpy-backed Series/Index), NumpyExtensionArray.searchsorted, BaseMaskedArray.searchsorted, and ArrowExtensionArray.searchsorted.

Test plan

  • New tests for numpy-backed numeric/bool dtypes (int64, float64, uint8, bool) × 12 incompatible value types
  • New tests for nullable dtypes (Int64, Float64, boolean)
  • New tests for Arrow numeric dtype (int64[pyarrow])
  • New tests for NumpyExtensionArray path
  • Verified existing searchsorted tests still pass (datetime, timedelta, period, categorical, extension)

🤖 Generated with Claude Code

Remove the duplicate searchsorted definition that called super()
(which goes through _validate_setitem_value, too strict for searchsorted).
Add validate_searchsorted_value to the existing method that correctly
bypasses _validate_setitem_value by delegating to numpy directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant