Skip to content

Commit ed58eec

Browse files
committed
Updated return val and test cases
1 parent 024810f commit ed58eec

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pandas/core/indexes/base.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1878,14 +1878,7 @@ def get_duplicates(self):
18781878
"idx[idx.duplicated()].unique() instead",
18791879
FutureWarning, stacklevel=2)
18801880

1881-
return self._get_duplicates()
1882-
1883-
def _get_duplicates(self):
1884-
from collections import defaultdict
1885-
counter = defaultdict(lambda: 0)
1886-
for k in self.values:
1887-
counter[k] += 1
1888-
return sorted(k for k, v in compat.iteritems(counter) if v > 1)
1881+
return self[self.duplicated()].unique()
18891882

18901883
def _cleanup(self):
18911884
self._engine.clear_mapping()

pandas/tests/indexes/test_multi.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,8 @@ def check(nlevels, with_nulls):
24132413
for a in [101, 102]:
24142414
mi = MultiIndex.from_arrays([[101, a], [3.5, np.nan]])
24152415
assert not mi.has_duplicates
2416-
assert mi.get_duplicates() == []
2416+
assert mi.get_duplicates().equals(
2417+
MultiIndex.from_arrays([[], []]))
24172418
tm.assert_numpy_array_equal(mi.duplicated(), np.zeros(
24182419
2, dtype='bool'))
24192420

@@ -2425,7 +2426,8 @@ def check(nlevels, with_nulls):
24252426
labels=np.random.permutation(list(lab)).T)
24262427
assert len(mi) == (n + 1) * (m + 1)
24272428
assert not mi.has_duplicates
2428-
assert mi.get_duplicates() == []
2429+
assert mi.get_duplicates().equals(
2430+
MultiIndex.from_arrays([[], []]))
24292431
tm.assert_numpy_array_equal(mi.duplicated(), np.zeros(
24302432
len(mi), dtype='bool'))
24312433

0 commit comments

Comments
 (0)