Skip to content

Commit

Permalink
feat(python): deprecate boolean mask for Series indexing (#5075)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosantama committed Oct 2, 2022
1 parent d192e3f commit 982d4b5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion py-polars/polars/internals/series/series.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import math
import warnings
from datetime import date, datetime, time, timedelta
from typing import TYPE_CHECKING, Any, Callable, NoReturn, Sequence, Union
from typing import TYPE_CHECKING, Any, Callable, NoReturn, Sequence, Union, overload
from warnings import warn

from polars import internals as pli
Expand Down Expand Up @@ -624,6 +625,17 @@ def _pos_idxs(self, idxs: np.ndarray[Any, Any] | Series) -> Series:

raise NotImplementedError("Unsupported idxs datatype.")

@overload
def __getitem__(self, item: int) -> Any:
...

@overload
def __getitem__(
self,
item: Series | range | slice | np.ndarray[Any, Any] | list[int] | list[bool],
) -> Series:
...

def __getitem__(
self,
item: int
Expand All @@ -634,6 +646,16 @@ def __getitem__(
| list[int]
| list[bool],
) -> Any:
if (
is_bool_sequence(item)
or (isinstance(item, Series) and item.dtype == Boolean)
or (isinstance(item, np.ndarray) and item.dtype.kind == "b")
):
warnings.warn(
"passing a boolean mask to Series.__getitem__ is being deprecated; "
"instead use Series.filter",
category=DeprecationWarning,
)
if isinstance(item, int):
if item < 0:
item = self.len() + item
Expand Down

0 comments on commit 982d4b5

Please sign in to comment.