Skip to content

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

Merged
merged 23 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1582840
Replaced ValueError exception with TypeError exception in df.where() …
DarthKitten2130 Dec 14, 2023
395b1c5
Updated test_where.py to account for updated exceptions.
DarthKitten2130 Dec 14, 2023
c071193
Update test_indexing.py to account for modified exceptions
DarthKitten2130 Dec 14, 2023
7d9af8c
Update test_where.py for series
DarthKitten2130 Dec 15, 2023
7c459dc
Merge branch 'main' into 56330
DarthKitten2130 Dec 18, 2023
06ff5c8
Added bug fix to v2.2.0.rst
DarthKitten2130 Dec 21, 2023
b7fca65
Updated v2.2.0.rst
DarthKitten2130 Dec 21, 2023
1061779
Merge branch 'main' into 56330
DarthKitten2130 Dec 21, 2023
2e0f28e
Updated v2.2.0.rst
DarthKitten2130 Dec 21, 2023
f1f12d5
Updated v2.2.0.rst
DarthKitten2130 Dec 21, 2023
7dcb852
Updated v2.2.0.rst
DarthKitten2130 Dec 26, 2023
79e13c4
Updated v2.2.0.rst
DarthKitten2130 Dec 27, 2023
67f3945
resolved merge conflict
DarthKitten2130 Dec 28, 2023
2aa6ae6
hi
DarthKitten2130 Dec 28, 2023
cc35698
resolved conflicts again
DarthKitten2130 Dec 28, 2023
c4ef073
Updated v2.2.0.rst
DarthKitten2130 Dec 28, 2023
005e41c
Updated v2.2.0.rst
DarthKitten2130 Dec 28, 2023
a53832c
Merge branch 'main' into 56330
DarthKitten2130 Dec 29, 2023
05dc2df
Merge branch 'main' into 56330
DarthKitten2130 Dec 30, 2023
3bd0619
removed change from 2.20
DarthKitten2130 Jan 15, 2024
36091e5
Merge branch 'pandas-dev:main' into 56330
DarthKitten2130 Jan 15, 2024
592b1d7
Update v2.3.0.rst
DarthKitten2130 Jan 15, 2024
86c8561
Update doc/source/whatsnew/v2.3.0.rst
DarthKitten2130 Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Copy link
Member

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?

- Bug in rendering ``inf`` values inside a :class:`DataFrame` with the ``use_inf_as_na`` option enabled (:issue:`55483`)
- Bug in rendering a :class:`Series` with a :class:`MultiIndex` when one of the index level's names is 0 not having that name displayed (:issue:`55415`)
- Bug in the error message when assigning an empty :class:`DataFrame` to a column (:issue:`55956`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10655,11 +10655,11 @@ def _where(
if not isinstance(cond, ABCDataFrame):
# This is a single-dimensional object.
if not is_bool_dtype(cond):
raise ValueError(msg.format(dtype=cond.dtype))
raise TypeError(msg.format(dtype=cond.dtype))
else:
for _dt in cond.dtypes:
if not is_bool_dtype(_dt):
raise ValueError(msg.format(dtype=_dt))
raise TypeError(msg.format(dtype=_dt))
if cond._mgr.any_extension_types:
# GH51574: avoid object ndarray conversion later on
cond = cond._constructor(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_getitem_boolean(self, mixed_float_frame, mixed_int_frame, datetime_fram
subframe_obj = datetime_frame[indexer_obj]
tm.assert_frame_equal(subframe_obj, subframe)

with pytest.raises(ValueError, match="Boolean array expected"):
with pytest.raises(TypeError, match="Boolean array expected"):
datetime_frame[datetime_frame]

# test that Series work
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_where_invalid_input_single(self, cond):
df = DataFrame({"a": [1, 2, 3]})
msg = "Boolean array expected for the condition"

with pytest.raises(ValueError, match=msg):
with pytest.raises(TypeError, match=msg):
df.where(cond)

@pytest.mark.parametrize(
Expand All @@ -272,7 +272,7 @@ def test_where_invalid_input_multiple(self, cond):
df = DataFrame({"a": [1, 2, 3], "b": [2, 2, 2]})
msg = "Boolean array expected for the condition"

with pytest.raises(ValueError, match=msg):
with pytest.raises(TypeError, match=msg):
df.where(cond)

def test_where_dataframe_col_match(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_where_invalid_input(cond):
s = Series([1, 2, 3])
msg = "Boolean array expected for the condition"

with pytest.raises(ValueError, match=msg):
with pytest.raises(TypeError, match=msg):
s.where(cond)

msg = "Array conditional must be same shape as self"
Expand Down