Skip to content

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

Closed
wants to merge 10 commits into from
Closed

BUG/TST: Add searchsorted tests #32874

wants to merge 10 commits into from

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Mar 20, 2020

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

xref: #32845

@jbrockmendel
Copy link
Member

LGTM

@jbrockmendel jbrockmendel added the Testing pandas testing functions or related to the test suite label Mar 21, 2020
tm.assert_numpy_array_equal(result, expected)


@pytest.mark.parametrize(
Copy link
Contributor

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)

Copy link
Contributor

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(
Copy link
Contributor

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

@jreback jreback added this to the 1.1 milestone Mar 21, 2020
@@ -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)):
Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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

@dsaxton dsaxton changed the title TST: Add IntervalIndex.searchsorted tests BUG/TST: Add searchsorted tests Mar 22, 2020
["2014-01-01", "2014-01-02", "2014-01-03", "2014-01-04", "2014-01-05"],
freq="D",
)
result = pidx.searchsorted(klass(pidx))
Copy link
Member

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))
Copy link
Member

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)):
Copy link
Contributor

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)):
Copy link
Contributor

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?

@dsaxton
Copy link
Member Author

dsaxton commented Mar 22, 2020

Carried over to #32764 since there's overlap

@dsaxton dsaxton closed this Mar 22, 2020
@dsaxton dsaxton deleted the idx-search-sorted branch March 22, 2020 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants