diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e46a0aa044b6d..e5ebfbec75401 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10683,11 +10683,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( diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 3d36d0471f02f..c0b15c849594e 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -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( @@ -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): @@ -294,7 +294,7 @@ def test_where_ndframe_align(self): df = DataFrame([[1, 2, 3], [4, 5, 6]]) cond = [True] - with pytest.raises(ValueError, match=msg): + with pytest.raises(TypeError, match=msg): df.where(cond) expected = DataFrame([[1, 2, 3], [np.nan, np.nan, np.nan]]) @@ -303,7 +303,7 @@ def test_where_ndframe_align(self): tm.assert_frame_equal(out, expected) cond = np.array([False, True, False, True]) - with pytest.raises(ValueError, match=msg): + with pytest.raises(TypeError, match=msg): df.where(cond) expected = DataFrame([[np.nan, np.nan, np.nan], [4, 5, 6]])