Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

seth-p
Copy link
Contributor

@seth-p seth-p commented May 12, 2015

Closes #10115.

@@ -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:
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels May 13, 2015
@jreback jreback added this to the 0.17.0 milestone May 13, 2015
if self.name is not None:
return self._constructor(result, name=self.name)
else:
return self._constructor(result, names=self.names)
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@jreback
Copy link
Contributor

jreback commented May 21, 2015

@seth-p can you rebase and update?

@seth-p
Copy link
Contributor Author

seth-p commented Jun 16, 2015

Afraid I do not have time to work on this. Could someone else handle it?

@sinhrks
Copy link
Member

sinhrks commented Jun 16, 2015

@seth-p OK, will do.

@seth-p seth-p deleted the drop_duplicates_names branch August 7, 2015 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: MultiIndex.drop_duplicates() drops names
4 participants