Skip to content

Commit

Permalink
CLN: Enforce empty bool indexer deprecation (pandas-dev#58390)
Browse files Browse the repository at this point in the history
* CLN: Enforce empty bool indexer deprecation

* Add whatsnew entry
  • Loading branch information
Aloqeely committed Apr 23, 2024
1 parent 8aa4f0e commit e9b0a3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ Removal of prior version deprecations/changes
- Disallow automatic casting to object in :class:`Series` logical operations (``&``, ``^``, ``||``) between series with mismatched indexes and dtypes other than ``object`` or ``bool`` (:issue:`52538`)
- Disallow calling :meth:`Series.replace` or :meth:`DataFrame.replace` without a ``value`` and with non-dict-like ``to_replace`` (:issue:`33302`)
- Disallow constructing a :class:`arrays.SparseArray` with scalar data (:issue:`53039`)
- Disallow indexing an :class:`Index` with a boolean indexer of length zero, it now raises ``ValueError`` (:issue:`55820`)
- Disallow non-standard (``np.ndarray``, :class:`Index`, :class:`ExtensionArray`, or :class:`Series`) to :func:`isin`, :func:`unique`, :func:`factorize` (:issue:`52986`)
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)
Expand Down
9 changes: 3 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5033,12 +5033,9 @@ def __getitem__(self, key):

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

result = getitem(key)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def test_empty_fancy(self, index, dtype, request, using_infer_string):

assert index[[]].identical(empty_index)
if dtype == np.bool_:
with tm.assert_produces_warning(FutureWarning, match="is deprecated"):
with pytest.raises(ValueError, match="length of the boolean indexer"):
assert index[empty_arr].identical(empty_index)
else:
assert index[empty_arr].identical(empty_index)
Expand Down

0 comments on commit e9b0a3c

Please sign in to comment.