Skip to content

[DEPR]: Remove numeric cross-kind casting in label-based lookup #53613

@wence-

Description

@wence-

As seen in discussions in #53290, cross-kind casting cannot be made to do the "right" thing in the sense of getting out what you think you put in.

One comment from the discussion in that issue:

So this isn't a bug, but a result of indexing with big floats on integer indexes (which you shouldn't do)

I agree with this statement, and suggest that pandas should make it impossible to do this, by not supporting casting between numeric kinds in label-based lookup.

Rationale:

  • If no-one should do it anyway, then it is not a big loss if they can't.
  • It's actually very difficult to make the label lookup behave in a way that is consistent with a simple mental model, since cross-kind casting leads to value-dependent behaviour changes. Moreover, the rules as implemented are not symmetric: looking up a lossily-casted integer in a float index does not produce the same results as if one had that integer in the index and looked up with the matching float.

Other possible approaches

Maintain cross-kind casting, but at least try and tighten up the casting behaviour so that "find float in int index" and "find int in float index" behave symmetrically and self-consistently wrt passing array-like or scalar-like arguments (this was the original reason for reporting #53290).

Metadata

Metadata

Assignees

Labels

DeprecateFunctionality to remove in pandasDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselves

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions