-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
BUG/TST: Add searchsorted tests #32874
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
LGTM |
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize( |
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 a Timedelta & Period test cases here as well (followon PR is ok)
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.
actually if you'd do in this one
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize( |
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.
actually if you'd do in this one
pandas/core/arrays/datetimelike.py
Outdated
@@ -804,6 +804,16 @@ def searchsorted(self, value, side="left", sorter=None): | |||
indices : array of ints | |||
Array of insertion points with the same shape as `value`. | |||
""" | |||
if is_list_like(value) and not isinstance(value, type(self)): |
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.
The tests added for PeriodIndex were failing so had to include this bug fix
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.
does this need to go before the str and _recognized_scalar checks below? IIRC putting them in this order is a pattern in this and related modules
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 don't think so, can move it down below
["2014-01-01", "2014-01-02", "2014-01-03", "2014-01-04", "2014-01-05"], | ||
freq="D", | ||
) | ||
result = pidx.searchsorted(klass(pidx)) |
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 repeat this with pidx._data.searchsorted
def test_searchsorted_different_argument_classes(klass): | ||
# https://github.com/pandas-dev/pandas/issues/32762 | ||
values = IntervalIndex([Interval(0, 1), Interval(1, 2)]) | ||
result = values.searchsorted(klass(values)) |
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 repeat with values._data.searchsorted
if not type(self)._is_recognized_dtype(value): | ||
raise TypeError( | ||
"searchsorted requires compatible dtype or scalar, " | ||
f"not {type(value).__name__}" | ||
) | ||
value = type(self)(value) | ||
self._check_compatible_with(value) | ||
|
||
if not (isinstance(value, (self._scalar_type, type(self))) or (value is NaT)): |
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.
is this line actually hit by anything? 858), this seems very duplicative
@@ -846,14 +846,14 @@ def searchsorted(self, value, side="left", sorter=None): | |||
elif isinstance(value, self._recognized_scalars): | |||
value = self._scalar_type(value) | |||
|
|||
elif isinstance(value, np.ndarray): | |||
if is_list_like(value) and not isinstance(value, type(self)): |
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 this be an elif?
Carried over to #32764 since there's overlap |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
xref: #32845