API: Should Index.where/insert raise or cast on invalid other? #37594
Labels
API - Consistency
Internal Consistency of API/Behavior
Needs Discussion
Requires discussion from core team before further action
Index.where
ATM
index.where(mask, something_incompatible)
raises for EA-backed indexes and MultiIndex and casts (sometimes buggily xref #37591) for everything else.These should all do the same thing. I lean towards raising rather than casting. Doing that breaks a handful of tests, but AFAICT they are all directly testing Index.where, so not used by other parts of the code.
Index.insert
CategoricalIndex and IntervalIndex raise on invalid, PeriodIndex casts to object, DatetimeIndex and TimedeltaIndex cast to object only for strings and otherwise raise. The base class casts but uses _coerce_scalar_to_index instead of any of our more standard patterns.
If changed to always raise, 25 tests fail. Most of these are directly testing Index.insert so could be changed if the API changed. The main troubling one is test_pivot_periods_with_margins, which I haven't tracked down all the way.
Index.putmask I'm still getting a handle on
The text was updated successfully, but these errors were encountered: