Skip to content

Seth p drop duplicates names #1

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ doc/_build
dist
# Egg metadata
*.egg-info
.eggs
# tox testing tool
.tox
# rope
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ Bug Fixes

- Bug in ``Timestamp``'s' ``microsecond``, ``quarter``, ``dayofyear``, ``week`` and ``daysinmonth`` properties return ``np.int`` type, not built-in ``int``. (:issue:`10050`)
- Bug in ``NaT`` raises ``AttributeError`` when accessing to ``daysinmonth``, ``dayofweek`` properties. (:issue:`10096`)

- Bug in ``drop_duplicates`` dropping name(s) (:issue:`10115`)


4 changes: 1 addition & 3 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,14 +2579,12 @@ 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)
return super(Index, self).drop_duplicates(take_last=take_last)

@Appender(_shared_docs['duplicated'] % _index_doc_kwargs)
def duplicated(self, take_last=False):
return super(Index, self).duplicated(take_last=take_last)


def _evaluate_with_timedelta_like(self, other, op, opstr):
raise TypeError("can only perform ops with timedelta like values")

Expand Down
25 changes: 24 additions & 1 deletion pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,19 @@ def test_duplicates(self):

if not len(ind):
continue
if isinstance(ind, MultiIndex):
continue
idx = self._holder([ind[0]]*5)
self.assertFalse(idx.is_unique)
self.assertTrue(idx.has_duplicates)

# GH 10115
# preserve names
idx.name = 'foo'
result = idx.drop_duplicates()
self.assertEqual(result.name, 'foo')
self.assert_index_equal(result, Index([ind[0]],name='foo'))

def test_sort(self):
for ind in self.indices.values():
self.assertRaises(TypeError, ind.sort)
Expand Down Expand Up @@ -1695,9 +1704,10 @@ def test_reindexing(self):

def test_duplicates(self):

idx = CategoricalIndex([0, 0, 0])
idx = CategoricalIndex([0, 0, 0],name='foo')
self.assertFalse(idx.is_unique)
self.assertTrue(idx.has_duplicates)
self.assertEqual(idx.name,'foo')

def test_get_indexer(self):

Expand Down Expand Up @@ -4410,6 +4420,19 @@ def check(nlevels, with_nulls):
self.assert_array_equal(mi.duplicated(),
np.zeros(len(mi), dtype='bool'))

def test_duplicate_meta_data(self):
# GH 10115
index = MultiIndex(levels=[[0, 1], [0, 1, 2]],
labels=[[0, 0, 0, 0, 1, 1, 1],
[0, 1, 2, 0, 0, 1, 2]])
for idx in [index,
index.set_names([None, None]),
index.set_names([None, 'Num']),
index.set_names(['Upper','Num']),
]:
self.assertTrue(idx.has_duplicates)
self.assertEqual(idx.drop_duplicates().names, idx.names)

def test_tolist(self):
result = self.index.tolist()
exp = list(self.index.values)
Expand Down