Skip to content

[DISC] Index[object] ops #21315

Closed
Closed
@jbrockmendel

Description

@jbrockmendel

My understanding is that Index[object] was originally written with strings in mind, which is why ops like __sub__ and __neg__ don't make sense. Since we've got more non-string cases (e.g. #21314), what if instead these were defined something like:

def __neg__(self):
    return Index([-x for x in self])

def __sub__(self, other):  # hand-wave appropriate handling for scalar vs vector other
    return Index([x - other for x in self])

The string cases would still raise, but for things like Decimal and DateOffset we could get the "natural" behavior. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds 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