Skip to content

Commit e9b0a3c

Browse files
authored
CLN: Enforce empty bool indexer deprecation (#58390)
* CLN: Enforce empty bool indexer deprecation * Add whatsnew entry
1 parent 8aa4f0e commit e9b0a3c

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Removal of prior version deprecations/changes
222222
- Disallow automatic casting to object in :class:`Series` logical operations (``&``, ``^``, ``||``) between series with mismatched indexes and dtypes other than ``object`` or ``bool`` (:issue:`52538`)
223223
- Disallow calling :meth:`Series.replace` or :meth:`DataFrame.replace` without a ``value`` and with non-dict-like ``to_replace`` (:issue:`33302`)
224224
- Disallow constructing a :class:`arrays.SparseArray` with scalar data (:issue:`53039`)
225+
- Disallow indexing an :class:`Index` with a boolean indexer of length zero, it now raises ``ValueError`` (:issue:`55820`)
225226
- Disallow non-standard (``np.ndarray``, :class:`Index`, :class:`ExtensionArray`, or :class:`Series`) to :func:`isin`, :func:`unique`, :func:`factorize` (:issue:`52986`)
226227
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
227228
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)

pandas/core/indexes/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,12 +5033,9 @@ def __getitem__(self, key):
50335033

50345034
if not isinstance(self.dtype, ExtensionDtype):
50355035
if len(key) == 0 and len(key) != len(self):
5036-
warnings.warn(
5037-
"Using a boolean indexer with length 0 on an Index with "
5038-
"length greater than 0 is deprecated and will raise in a "
5039-
"future version.",
5040-
FutureWarning,
5041-
stacklevel=find_stack_level(),
5036+
raise ValueError(
5037+
"The length of the boolean indexer cannot be 0 "
5038+
"when the Index has length greater than 0."
50425039
)
50435040

50445041
result = getitem(key)

pandas/tests/indexes/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def test_empty_fancy(self, index, dtype, request, using_infer_string):
481481

482482
assert index[[]].identical(empty_index)
483483
if dtype == np.bool_:
484-
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
484+
with pytest.raises(ValueError, match="length of the boolean indexer"):
485485
assert index[empty_arr].identical(empty_index)
486486
else:
487487
assert index[empty_arr].identical(empty_index)

0 commit comments

Comments
 (0)