Skip to content

ENH: MultiIndex.dtypes #37062

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

Closed
jreback opened this issue Oct 11, 2020 · 4 comments · Fixed by #37073
Closed

ENH: MultiIndex.dtypes #37062

jreback opened this issue Oct 11, 2020 · 4 comments · Fixed by #37073
Labels
Enhancement good first issue MultiIndex Needs Triage Issue that has not been reviewed by a pandas team member
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Oct 11, 2020

create a mi

In [13]: mi = pd.MultiIndex.from_product([[1,2,3], list('abc'), pd.date_range('20200101', periods=2, tz='UTC')], names=['int', 'string', 'dt'])                            

You can already get .dtypes, but is slightly cumbersome. I would propose adding Multidex.dtypes (we already have MultiIndex.dtype but its always object). I think this is worth the convenience api.

In [14]: mi.to_frame().dtypes                                                                                                                                              
Out[14]: 
int                     int64
string                 object
dt        datetime64[ns, UTC]
dtype: object

# we would actually implement like this.
In [15]: pd.Series({l.name: l.dtype for l in mi.levels})                                                                                                                   
Out[15]: 
int                     int64
string                 object
dt        datetime64[ns, UTC]
dtype: object
@jreback jreback added Enhancement MultiIndex good first issue Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 11, 2020
@jreback jreback added this to the Contributions Welcome milestone Oct 11, 2020
@abdur-n-tr
Copy link

Hi, @jreback I could give a try to implement MultiIndex.dtypes, if that's okay ?

@jreback
Copy link
Contributor Author

jreback commented Oct 25, 2020

there is already a PR out for this

@abdur-n-tr
Copy link

I filtered the issues with no-assignee and this also came under that tag. I am a newbie here so anyone can guide how I can find the issues that need to be resolved yet.

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 11, 2020
@Aloqeely
Copy link
Member

(we already have MultiIndex.dtype but its always object)

May I ask why is that the case? Why does it not go for the "smallest" dtype that covers all the dtypes in the multiindex, so if it has dtypes: int, float then mi.dtype returns float?

If there's no specific reason then I'll open an enhancement request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement good first issue MultiIndex Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants