-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Replaced ValueError exception with TypeError exception in df.where() function #56495
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
…function Replaced ValueError exception with TypeError as it is more appropriate for the error it serves.
You have to adjust one more test here: https://github.com/pandas-dev/pandas/blob/main/pandas/tests/series/indexing/test_where.py#L204 |
Thank you so much! Finally passed the checks! |
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 whatsnew entry in v2.20.rst?
|
doc/source/whatsnew/v2.2.0.rst
Outdated
@@ -896,6 +896,7 @@ Other | |||
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) | |||
- Bug in :meth:`DataFrame.from_dict` which would always sort the rows of the created :class:`DataFrame`. (:issue:`55683`) | |||
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` raising a ``ValueError`` (:issue:`56478`) | |||
- Bug in :meth:`DataFrame.where()` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`) |
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.
Could you move this to v3.0.0.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.
One comment otherwise looks good
Co-authored-by: Matthew Roeschke <[email protected]>
Thanks @DarthKitten2130 |
…re() function (pandas-dev#56495) * Replaced ValueError exception with TypeError exception in df.where() function Replaced ValueError exception with TypeError as it is more appropriate for the error it serves. * Updated test_where.py to account for updated exceptions. * Update test_indexing.py to account for modified exceptions * Update test_where.py for series * Added bug fix to v2.2.0.rst * Updated v2.2.0.rst * Updated v2.2.0.rst * Updated v2.2.0.rst * Updated v2.2.0.rst * Updated v2.2.0.rst * resolved merge conflict * resolved conflicts again * Updated v2.2.0.rst * Updated v2.2.0.rst * removed change from 2.20 * Update v2.3.0.rst * Update doc/source/whatsnew/v2.3.0.rst Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Matthew Roeschke <[email protected]>
Replaced ValueError exception with TypeError as it is more appropriate for the error it serves
[] closes issue #56330 where there was a consensus that a TypeError is more appropriate for the following error: "Boolean array expected for the condition, not (non-bool type)". Since ValueErrors are raised when the type is correct but the value is incorrect, whereas in this function we are raising an exception because of a wrong type, hence the TypeError.
I've also included commits to update the tests for this method.
(I had already made this PR but messed up my commits because I'm new to GitHub so I'm redoing it).