-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bug: Fix Inconsistent Behavior for Series.searchsorted #49706
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
Raise error when DataFrame is passed to searchsorted
This reverts commit 0b1b450.
This reverts commit 090bd79.
Raise error when DataFrame is passed to searchsorted
pandas/core/base.py
Outdated
@@ -1270,6 +1271,13 @@ def searchsorted( | |||
sorter: NumpySorter = None, | |||
) -> npt.NDArray[np.intp] | np.intp: | |||
|
|||
if isinstance(value, pd.DataFrame): |
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.
check with ABCDataFrame
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 am not sure about the usage of ABCDataFrame. Does that mean I should use isinstance(value, ABCDataFrame)
instead?
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.
yes. at the top do from pandas.core.dtypes.generic import ABCDataFrame
needs test |
Raise error when DataFrame is passed to searchsorted
pandas/core/base.py
Outdated
@@ -1270,6 +1270,13 @@ def searchsorted( | |||
sorter: NumpySorter = None, | |||
) -> npt.NDArray[np.intp] | np.intp: | |||
|
|||
if isinstance(value, ABCDataFrame): | |||
msg = ( | |||
"Value must be array-like or scalar, " |
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 "1D" here
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 have added 1-D. In fact, n-D object except DataFrame works well with this function. As long as we don't call pd.array(n-d DataFrame)
.
there's another subtle bug you've uncovered
|
@@ -65,3 +67,10 @@ def test_searchsorted_sorter(self): | |||
res = ser.searchsorted([0, 3], sorter=np.argsort(ser)) | |||
exp = np.array([0, 2], dtype=np.intp) | |||
tm.assert_numpy_array_equal(res, exp) | |||
|
|||
def test_searchsorted_Dataframe_fail(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 you de-capitalize "DataFrame" here, and add a comment # GH#49620
on the nex tline
That's exactly the real problem. The reason why DataFrame should be forbidden here is that type infer in |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
@mroeschke i think this might be fine as-is; i can do a separate PR to fix pd.array |
Thanks @yqyqyq-W |
Series.searchsorted(...)
fails withTimestamp
DataFrame
s #49620doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.