Skip to content

ENH: initialising MultiIndex with a dtypes param #54523

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

Open
1 of 3 tasks
attack68 opened this issue Aug 13, 2023 · 1 comment
Open
1 of 3 tasks

ENH: initialising MultiIndex with a dtypes param #54523

attack68 opened this issue Aug 13, 2023 · 1 comment

Comments

@attack68
Copy link
Contributor

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

See #54521 for the motivating example.

We can currently set the dtype on an Index but there is no dtypes argument for a MultiIndex.from_tuples.
Perhaps it is enough to document how to achieve the equivalent of from_tuples by using from_arrays where the arrays are Index with a dtype set.

Feature Description

.

Alternative Solutions

.

Additional Context

.

@attack68 attack68 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 13, 2023
@chaoyihu
Copy link
Contributor

chaoyihu commented Jul 13, 2024

Thanks for proposing the workaround! It works for a user case mentioned in issue 59003. I will open a PR to document it.

Despite the workaround, I think initializing MultiIndex with a dtypes param should still be supported. Currently the MultiIndex constructor has a dtype parameter in its function signature, but the parameter is never accessed in the function logic. To me this seems to indicate that initializing with a dtypes param is intended, just waiting to be implemented.

The helper functions including from_arrays(), from_tuples(), from_product(), and from_frame() rely on the MultiIndex
class constructor, thus they do not take parameter for dtypes. Once relevant logic is added to the class constructor, the helper functions can also be updated.

@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants