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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).

# 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

return MultiIndex.from_tuples(values, names=names, **kwargs)

result = self.copy(**kwargs)
result._cache = self._cache.copy()
# GH32669
if "levels" in result._cache:
del result._cache["levels"]
result._cache.pop("levels", None) # GH32669
return result

def _shallow_copy_with_infer(self, values, **kwargs):
Expand Down