Closed
Description
Describe the bug
Series.loc
does not accept a lambda (or more generally a Callable[[Any], Any]
) to filter the rows. of getitem.
I suspected this is the case for pd.DataFrame
too, but I haven't tested it.
To Reproduce
import pandas as pd
s = pd.Series([1, 2])
filtered = s.loc[lambda x: x > 1]
Using mypy
.
Error message:
test_loc_with_callable.py:7: error: No overload variant of "__getitem__" of "_LocIndexerSeries" matches argument type "Callable[[Any], Any]" [call-overload]
filtered = s.loc[lambda x: x > 1]
Please complete the following information:
- OS: Linux
- OS Version: output of
uname -a
:5.14.0-1058-oem #66-Ubuntu SMP Fri Feb 10 09:46:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- python version: Python 3.9.5
- version of type checker:
mypy 1.1.1
- version of installed
pandas-stubs
:1.5.3.230304