Skip to content

CLN: simplify MultiIndex._shallow_copy #32772

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

Merged
merged 1 commit into from
Mar 19, 2020

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Mar 17, 2020

Minor simplification of MultiIndex._shallow_copy.

@topper-123 topper-123 force-pushed the clean_multiindex_shallow_copy branch from 713db7c to fb4f8ec Compare March 17, 2020 08:19
@@ -990,15 +990,11 @@ def _constructor(self):
def _shallow_copy(self, values=None, **kwargs):
if values is not None:
names = kwargs.pop("names", kwargs.pop("name", self.names))
# discards freq
kwargs.pop("freq", None)
Copy link
Contributor Author

@topper-123 topper-123 Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping this silently makes no sense, freq isn't accepted by any MultiIndex constructor. Just let it be passed in and raise a TypeError if encountered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@jbrockmendel
Copy link
Member

LGTM

@@ -990,15 +990,11 @@ def _constructor(self):
def _shallow_copy(self, values=None, **kwargs):
if values is not None:
names = kwargs.pop("names", kwargs.pop("name", self.names))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to worry about both name and names being passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultiIndex.from_tuples only accepts names, and Mi uses name in some locations, so yes (but it a part of the ickyness of MultiIndex, so should ideally be refactored away).

@topper-123 topper-123 added this to the 1.1 milestone Mar 17, 2020
@jreback jreback merged commit 673b1f8 into pandas-dev:master Mar 19, 2020
@jreback
Copy link
Contributor

jreback commented Mar 19, 2020

thanks @topper-123

@topper-123 topper-123 deleted the clean_multiindex_shallow_copy branch March 21, 2020 11:45
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 23, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants