Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Index vs Series constructor alignment #49372

Closed
6 of 8 tasks
jbrockmendel opened this issue Oct 28, 2022 · 2 comments
Closed
6 of 8 tasks

API: Index vs Series constructor alignment #49372

jbrockmendel opened this issue Oct 28, 2022 · 2 comments
Labels
API Design Constructors Series/DataFrame/Index/pd.array Constructors

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 28, 2022

There has been long-running interest in aligning the behaviors of various constructors: e.g. #29973, #27460, #17246. But I don't see an issue that is specifically "Let's make Index behave like Series". So here goes.

Series goes through sanitize_array which calls a bunch of functions in core.dtypes.cast. Index uses casting/inference functions in indexes.base, as well as Index._ensure_array.

The remaining behavior differences AFAICT are:

(recently enforced deprecations including #49319, #49242, #48379 cut down on this a ton)

The first entry here (handling of non-round floats with inty dtype) would be the most invasive to align. The current Series behavior was in place before I got involved, so I'm not aware of the reasoning behind it. I'd be on board with deprecating it and changing it in 3.0.

Thoughts? cc @jorisvandenbossche @mroeschke @jreback @TomAugspurger @phofl

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member Constructors Series/DataFrame/Index/pd.array Constructors API Design and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 28, 2022
@jorisvandenbossche
Copy link
Member

Series(non_round_floats, dtype=inty) silently ignores dtype while Index raises

This relates very much to #45588, where I am arguing that we should change the casting / Series() behaviour to raise on float truncation (and essentially match what Index already does, apparently)

@jbrockmendel
Copy link
Member Author

This relates very much to #45588, where I am arguing that we should change the casting / Series() behaviour to raise on float truncation (and essentially match what Index already does, apparently)

Good point. Is there a viable strategy of addressing just Series(floaty, dtype=inty) without resolving all of #45588? Would doing so help cut down on the scope of that? (IIRC the scope there was somewhat daunting)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Constructors Series/DataFrame/Index/pd.array Constructors
Projects
None yet
Development

No branches or pull requests

2 participants