-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Fix regression for is_monotonic_increasing with nan in MultiIndex #37221
Conversation
def test_is_monotonic_with_nans(): | ||
# GH: 37220 | ||
idx = pd.MultiIndex.from_tuples([(np.nan,), (1,)], names=["test"]) | ||
assert idx.is_monotonic_increasing is False |
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.
Maybe parametrize over different positions for NaN
? I think it's probably correct to always return False here, although this is interesting:
[ins] In [32]: idx
Out[32]: Float64Index([nan, 1.0, 2.0], dtype='float64')
[ins] In [33]: idx.sort_values(ascending=True).is_monotonic_increasing
Out[33]: False
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.
That really is interesting. With 0.25.3
pd.MultiIndex.from_tuples([(1,), (np.nan,)], names=["test"]).is_monotonic_increasing
returned True
. We could change that, but that would be more than a Regression fix then?
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.
I think probably fine to call it a regression fix. I would say the previous behavior is not correct in this case (if monotone increasing means x <= y
for every adjacent pair of elements, then no sequence with NaN
values is monotone increasing, or decreasing for that matter), so we'd only want to fix the case with NaN
at the beginning rather than restoring the behavior completely.
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.
Thanks very much for the explanation. Adjusted the code accordingly.
� Conflicts: � doc/source/whatsnew/v1.1.4.rst
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.
Thanks @phofl
@phofl can you resolve conflict. |
� Conflicts: � doc/source/whatsnew/v1.1.4.rst
@simonjayhawkins Done |
this looks fine. can you run some asv's to see if any perf diffs here? (prob don't need to add, want to see the existing ones). |
Non monotonic indices increased (not surprising). No changes otherwise |
thanks @phofl |
@meeseeksdev backport 1.1.x |
…ing with nan in MultiIndex
…an in MultiIndex (#37446) Co-authored-by: patrick <61934744+phofl@users.noreply.github.com>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Found this while debugging a different issue.