Skip to content

Commit 0ebe048

Browse files
Aloqeelypmhatre1
authored andcommitted
CLN: Enforce empty bool indexer deprecation (pandas-dev#58390)
* CLN: Enforce empty bool indexer deprecation * Add whatsnew entry
1 parent b452a51 commit 0ebe048

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
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

+3-6
Original file line numberDiff line numberDiff line change
@@ -5014,12 +5014,9 @@ def __getitem__(self, key):
50145014

50155015
if not isinstance(self.dtype, ExtensionDtype):
50165016
if len(key) == 0 and len(key) != len(self):
5017-
warnings.warn(
5018-
"Using a boolean indexer with length 0 on an Index with "
5019-
"length greater than 0 is deprecated and will raise in a "
5020-
"future version.",
5021-
FutureWarning,
5022-
stacklevel=find_stack_level(),
5017+
raise ValueError(
5018+
"The length of the boolean indexer cannot be 0 "
5019+
"when the Index has length greater than 0."
50235020
)
50245021

50255022
result = getitem(key)

pandas/tests/indexes/test_base.py

+1-1
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)