-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: drop_duplicates drops name(s). #10116
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ doc/_build | |
dist | ||
# Egg metadata | ||
*.egg-info | ||
.eggs | ||
# tox testing tool | ||
.tox | ||
# rope | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2580,7 +2580,10 @@ def drop(self, labels, errors='raise'): | |
@Appender(_shared_docs['drop_duplicates'] % _index_doc_kwargs) | ||
def drop_duplicates(self, take_last=False): | ||
result = super(Index, self).drop_duplicates(take_last=take_last) | ||
return self._constructor(result) | ||
if self.name is not None: | ||
return self._constructor(result, name=self.name) | ||
else: | ||
return self._constructor(result, names=self.names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can dispense with this with a
e.g. this will propogate things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. though looking at this now, I think let me see if I can fix this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
@Appender(_shared_docs['duplicated'] % _index_doc_kwargs) | ||
def duplicated(self, take_last=False): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is for dealing with the API differences between Index and MultiIndex, yes? I think it would be cleaner to override the method on MultiIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. OK, I can do that.
Alternatively, it would be great if the constructors of all
Index
subclasses (other thanMultiIndex
) accepted anames
list of length one and used it to setname
. That way one could always just setnames
without worrying about it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would even be happy if you just explicitly check
isinstance(self, MultiIndex)
.I agree that your alternative solution would be preferable. That's part of a much bigger issue: #3268