-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: incorrect set_labels in MI #19058
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
Codecov Report
@@ Coverage Diff @@
## master #19058 +/- ##
==========================================
+ Coverage 91.53% 91.53% +<.01%
==========================================
Files 148 148
Lines 48688 48689 +1
==========================================
+ Hits 44566 44567 +1
Misses 4122 4122
Continue to review full report at Codecov.
|
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 looks ok, but pls add your original test (both with and w/o inplace) as well as a note in the whatsnew
cc @toobaz any thoughts here |
Looks good to me. As for tests, I guess it's just a matter of understanding what went wrong in this one, and fix it. |
you probably mean pandas/pandas/tests/indexes/test_multi.py Line 287 in 9303315
The issue with the test is that self.index has the same magnitude of categories in each level. (i.e. the length is each smaller than int8_max). So the misalignment does not have an effect. Also there is no misalignment if the labels get replaced in the first n levels.I would like to take care of the tests later. |
yep, sorry, actually this assertion: pandas/pandas/tests/indexes/test_multi.py Line 302 in 9303315
But I agree with your explanation. |
@Mofef tests need to be in the same issue as the PR fixing. |
@jreback Sorry I don't understand, you mean i should also add tests to this PR? In the meanwhile i looked into test_multi.py. My initial idea was to just increase the size of the minor level with something like def setup_method(self, method):
major_axis = Index(['foo', 'bar', 'baz', 'qux'])
minor_axis = Index(range(2, 128))
major_labels = np.random.choice(range(4), 128)
minor_labels = np.array(range(128))
... However, that doesn't seem to be feasible since a lot of test methods rely on the current "reference index". So I get ~50 presumably false negative tests. |
@Mofef yes you need a test, you can use the one that you put in the issue. you need to assert that this works (eg. construct the expected MI). |
Done. I had to define another test method, with its own I also stumbled upon #19092 Edit: I forgot about the whatsnew... |
pandas/tests/indexes/test_multi.py
Outdated
|
||
ind = pd.MultiIndex.from_tuples([(0, i) for i in range(130)]) | ||
new_labels = range(129, -1, -1) | ||
ind_reference = pd.MultiIndex.from_tuples( |
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.
call this expected
pandas/tests/indexes/test_multi.py
Outdated
|
||
# [w/o mutation] | ||
ind2 = ind.set_labels(labels=new_labels, level=1) | ||
assert_equal(ind2, ind_reference) |
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.
call these result, then you can simply do
assert result.equals(expected)
for the inplace case you need to copy before
pandas/tests/indexes/test_multi.py
Outdated
@@ -327,6 +327,28 @@ def assert_matching(actual, expected): | |||
assert_matching(ind2.labels, new_labels) | |||
assert_matching(self.index.labels, labels) | |||
|
|||
def test_set_label_distinctly_sized_levels(self): | |||
# label changing for levels of different magnitude of categories | |||
def assert_equal(actual, expected): |
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.
see below this is not necessary
Cool, thanks. PTAL |
looks good. ping on green. |
@jreback https://travis-ci.org/pandas-dev/pandas/jobs/325457802#L448
|
Sorry about the extra commits @Mofef. I fixed a merge conflict in the release notes and the CI services apparently had an issue with that. They're running again now. |
Oh ok no problem. thank you :) |
thanks @Mofef |
This fixes #19057