-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: boolean indexing error with .drop() #16877
Comments
From the current docs:
When you call I know that I am repeating part of what you said, but the documentation IMO seems to align with what it's supposed to do. Nowhere does it say that it filters by a conditional, which is what you were aiming to do. To perform the filtering that you want, one recommended way is this: df = df[df.bcol <= 2] Note that using |
this is a duplicate of #6189, but will keep this issue open. This is pretty easy to fix, by raising on a boolean indexer. PR's welcome! |
@jreback : I'm not sure what the problem is here. The documentation looks pretty clear on this. #6189 demonstrates that clearly. |
Well a boolean indexer doesn't make sense here and should raise an error. Having boolean indices is quite rare and you can also detect that case. |
@jreback : Is that not special-casing? |
its a fail-fast error check, if a boolean indexer is passed in, it should raise unless the axis is in fact a boolean index (and the shapes match). |
Fair enough. I feel like this should just be allowed, but given the confusion it's generated amongst users (two independent issues), I concede 😄 |
Hi, I'm working on this issue. |
…c and target is boolean (pandas-dev#16877)
…c and target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877)
…d target is boolean (pandas-dev#16877) (pandas-dev#17343)
…d target is boolean (pandas-dev#16877) (pandas-dev#17343)
Code Sample, a copy-pastable example if possible
Expected Output
Observed Output
Problem description
The anticipated behavior was that rows with
bcol
> 2 would be dropped. The actual behavior is that the boolean gets converted to 0/1, and then treated as index label. So row numbers 0 and/or 1 are dropped... but all other rows will be kept.The documentation did not make it clear what was happening.
Solutions might include documentation clarifying that
.drop()
cannot be used with boolean indexing, or a warning when receiving the (attempted) boolean index.Output of
pd.show_versions()
pandas: 0.20.2
pytest: 3.1.2
pip: 9.0.1
setuptools: 33.1.1.post20170320
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.1
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.5.0a1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.8.0
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.11
pymysql: 0.7.9.None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.9.5
s3fs: 0.1.1
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: