You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
importpandasaspdseries=pd.Series([1, 2, 3])
x=series[lambdas: s>2] # Indexing with a boolean function, works like a charmy=series[lambdas: True] # Indexing with a constant boolean function --> results in KeyError: True
Problem description
I would expect y to be equal to series in this example, because the callable function passed to __getitem__ returns True for all items in the Series. The same error arises when using a DataFrame. I know in this example, it seems like the function would be useless, because it would just return series, but in my use case the function that is passed to __getitem__ is actually a 'filter' function argument, and it would be very convenient to just turn off the filter by passing lambda df: True as the filter function.
The lambda function takes the whole Series as input (it's not a "mapping" operation that returns a Series of True values) and needs to return a valid indexer. In this case the scalar True is not a valid index so an error is raised. It seems you're expecting it to behave like
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
I would expect
y
to be equal toseries
in this example, because the callable function passed to__getitem__
returns True for all items in the Series. The same error arises when using a DataFrame. I know in this example, it seems like the function would be useless, because it would just returnseries
, but in my use case the function that is passed to__getitem__
is actually a 'filter' function argument, and it would be very convenient to just turn off the filter by passinglambda df: True
as the filter function.A quick workaround I found useful is:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-1030-aws
Version : #32~18.04.1-Ubuntu SMP Tue Jun 30 23:04:16 UTC 2020
machine : x86_64
processor :
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.1.1
Cython : 0.29.21
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.2.9
lxml.etree : None
html5lib : None
pymysql : 0.9.3
psycopg2 : 2.8.5 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fsspec : 0.7.4
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 0.17.1
pytables : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.15.1
xlrd : 1.2.0
xlwt : None
numba : 0.50.1
The text was updated successfully, but these errors were encountered: