-
- Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Index._searchsorted_monotonic(..., side='right') returns the left side position for monotonic decreasing indexes #17272
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
BUG: Index._searchsorted_monotonic(..., side='right') returns the left side position for monotonic decreasing indexes #17272
Conversation
That is correct. |
pandas/tests/indexes/test_base.py Outdated
| def test_searchsorted_monotonic(self): | ||
| # GH17271 | ||
| idx_inc = Index([0, 2, 4]) | ||
| idx_dec = Index([4, 2, 0]) |
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.
would be better to move these to common.py/Base as they be tested generically.
| expected = s.iloc[2:5] | ||
| tm.assert_series_equal(expected, s.loc[s >= 2]) | ||
| | ||
| # test endpoint of non-overlapping monotonic decreasing (GH16417) |
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 would instead make a specific test of this (also test increasing monotonic), even better would be to parametrize over closed (bonus points)
6378a27 to 436852e Compare Codecov Report
@@ Coverage Diff @@ ## master #17272 +/- ## =========================================== - Coverage 91.03% 40.25% -50.78% =========================================== Files 162 162 Lines 49567 49540 -27 =========================================== - Hits 45123 19944 -25179 - Misses 4444 29596 +25152
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@ ## master #17272 +/- ## ========================================== - Coverage 91.15% 91.14% -0.02% ========================================== Files 163 163 Lines 49591 49591 ========================================== - Hits 45207 45201 -6 - Misses 4384 4390 +6
Continue to review full report at Codecov.
|
| Notes regarding the review changes I made:
|
yes, pls just sort them if need; we don't use
simply add an xfailing test (with the issue number). |
| Okay, made those additional changes. EDIT: Nevermind, looks like codecov is fixed. |
b4ea216 to 1002aaa Compare | ping @jreback : made review related updates and did a rebase to resolve merge conflicts |
doc/source/whatsnew/v0.21.0.txt Outdated
| - Avoids ``IndexError`` when passing an Index or Series to ``.iloc`` with older numpy (:issue:`17193`) | ||
| - Allow unicode empty strings as placeholders in multilevel columns in Python 2 (:issue:`17099`) | ||
| - Bug in ``.iloc`` when used with inplace addition or assignment and an int indexer on a ``MultiIndex`` causing the wrong indexes to be read from and written to (:issue:`17148`) | ||
| - Bug in ``IntervalIndex`` where performing a scalar lookup fails for included right endpoints of non-overlapping monotonic decreasing indexes (:issue:`16417`) |
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.
can you add both issue numbers
pandas/tests/indexes/common.py Outdated
| value = index[0] | ||
| | ||
| if index.is_monotonic_increasing or index.is_monotonic_decreasing: | ||
| assert index._searchsorted_monotonic(value, side='left') == 0 |
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.
can you test .searchsorted() as well for the various cases
| | ||
| @pytest.mark.parametrize('direction, closed', | ||
| product(('increasing', 'decreasing'), | ||
| ('left', 'right', 'neither', 'both'))) |
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.
@zfrenchee if you'd have a look here
38b4971 to 361face Compare | Made the requested changes. A couple comments:
|
jreback left a comment
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.
minor request. lgtm. ping on green.
| if index.is_unique: | ||
| indexer = index.get_indexer(index[0:2]) | ||
| assert isinstance(indexer, np.ndarray) | ||
| assert indexer.dtype == np.intp |
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.
can you add what the result if not index.is_unique as well
| ping @jreback : checks are green Made one small additional change to the |
85ca734 to 1911860 Compare | ping @jreback : green again after rebasing to address the merge conflict. |
Fixed an issue where Index._searchsorted_monotonic(..., side='right') returns the left side position for monotonic decreasing indexes. Issue had a downstream effect on scalar lookups in IntervalIndex as well.
Removed xfail, as the issue impacting the failing test has been resolved. Rebase to address merge conflicts.
1911860 to 41e59d7 Compare | thanks @jschendel nice fixes! keep em coming! |
…t side position for monotonic decreasing indexes (pandas-dev#17272)
…t side position for monotonic decreasing indexes (pandas-dev#17272)
…t side position for monotonic decreasing indexes (pandas-dev#17272)
| indexer = index.get_indexer(index[0:2]) | ||
| assert isinstance(indexer, np.ndarray) | ||
| assert indexer.dtype == np.intp | ||
| if index.is_unique or isinstance(index, CategoricalIndex): |
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.
@jschendel why is CategoricalIndex excluded here?
git diff upstream/master -u -- "*.py" | flake8 --diffI didn't add a whatsnew entry for the
Index._searchsorted_monotonicfix, since it looks like past convention has been to not add whatsnew entries for private methods. Happy to add a whatsnew entry if I'm mistaken though. I did add a whatsnew entry for the downstream effect on IntervalIndex.