Skip to content

BUG: .unique() on MultiIndex: preserve names #20571

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

Merged
merged 1 commit into from
Apr 1, 2018

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented Mar 31, 2018

tm.assert_index_equal(res, exp)

# GH #20568 - empty MI
mi = pd.MultiIndex.from_arrays([[], []], names=['first', 'second'])
Copy link
Contributor

Choose a reason for hiding this comment

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

can u add a test w/o names as well

@codecov
Copy link

codecov bot commented Mar 31, 2018

Codecov Report

Merging #20571 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20571      +/-   ##
==========================================
- Coverage   91.84%   91.82%   -0.03%     
==========================================
  Files         152      152              
  Lines       49270    49269       -1     
==========================================
- Hits        45252    45239      -13     
- Misses       4018     4030      +12
Flag Coverage Δ
#multiple 90.2% <100%> (-0.03%) ⬇️
#single 41.9% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/multi.py 95.05% <100%> (-0.01%) ⬇️
pandas/plotting/_converter.py 65.07% <0%> (-1.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2ab407...9089b69. Read the comment docs.

@toobaz
Copy link
Member Author

toobaz commented Apr 1, 2018

@jreback ready to merge if there are no further comments

@@ -2483,6 +2493,11 @@ def test_unique_level(self, level):
expected = mi.get_level_values(level)
tm.assert_index_equal(result, expected)

# With empty MI
mi = pd.MultiIndex.from_arrays([[], []], names=['first', 'second'])
result = mi.unique(level=level)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this also solve the case where no level is specified?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the previous test does.

@jreback jreback added this to the 0.23.0 milestone Apr 1, 2018
@jreback
Copy link
Contributor

jreback commented Apr 1, 2018

lgtm. merge away @toobaz

@toobaz toobaz merged commit a77ac2b into pandas-dev:master Apr 1, 2018
@toobaz toobaz deleted the mi_empty_unique branch April 1, 2018 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.unique() drops names on MultiIndex BUG: TypeError when calling unique on empty MultiIndex
2 participants