-
-
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
Conversation
@@ -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: |
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 than MultiIndex
) accepted a names
list of length one and used it to set name
. That way one could always just set names
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
you can dispense with this with a
return self._shallow_copy(result)
, should handle all meta-data
e.g. this will propogate things like freq/tz
, etc as well.
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.
though looking at this now, I think MultiIndex._shallow_copy
is wrong
let me see if I can fix this
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.
@seth-p can you rebase and update? |
Afraid I do not have time to work on this. Could someone else handle it? |
@seth-p OK, will do. |
Closes #10115.