-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame.drop with empty DatetimeIndex behaves differently than passing empty Index #27994
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
Comments
Your example is equivalent to |
Thank you @mroeschke My initial thought was the issue is caused by duplicated values in index (i.e. df = pd.DataFrame(
{'value': [1, 2]},
index=[0, 0]
)
df = df.drop(df[df['value'] > 10].index) So I'm wondering if this difference was intentional. |
Ah I see. Thanks for the counter example. I agree then I would expected passing an empty |
Interestingly, I got
With that said, would it make sense to not raise these exceptions when passing empty list/index to If so, I might be able to contribute. |
Agreed with your conclusion, I think |
This looks to work on master now. Could use a test
|
@mroeschke I'm looking for an issue to pickup for my first contribution, was wondering if I could take this up. |
Yes go for it @mikephung122. |
@mroeschke I submitted a Pull Request (#42746) for this issue, could you take a look when you get the chance? |
fixed in #42746 |
Code Sample, a copy-pastable example if possible
Problem description
When calling
drop
for dataframe with DatetimeIndex, the function may raise an exception. See the following traceback:This can be avoided by not using
DataFrame.drop
like this:But nonetheless I'm reporting the issue as I expect
drop
to not raise the exception.Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 9f93d57
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.0-5-amd64
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.0.dev0+1184.g9f93d5702
numpy : 1.16.2
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.1.0
Cython : 0.29.13
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: