Skip to content

API: Should Index.where/insert raise or cast on invalid other? #37594

Closed
@jbrockmendel

Description

@jbrockmendel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions