Skip to content
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: Series.dt accessor throws exception after Series.drop when inplace=True #24408

Closed
aftersought opened this issue Dec 24, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@aftersought
Copy link

commented Dec 24, 2018

Code Sample, a copy-pastable example

import pandas as pd

z = pd.Series(pd.date_range('2018-01-01', periods=100))
z.drop(z[z.dt.weekday >= 4].index, inplace=True)

print(f"Length of z's index is {len(z.index)}, trying to access z.dt.date")
try:
    z.dt.date
except ValueError as e:
    print("Got error", e)

z.reset_index(inplace=True, drop=True)
print(f"Length of z's index is {len(z.index)}, trying to access z.dt.date")
try:
    z.dt.date
except ValueError as e:
    print("Got error", e)

yields:

Length of z's index is 58, trying to access z.dt.date
Got error Length of passed values is 58, index implies 100
Length of z's index is 58, trying to access z.dt.date
Got error Length of passed values is 58, index implies 100

Problem description

I don't understand why the code throws an exception and where the error message gets length of 100 when the index has been reset.

Expected Output

At least the second z.dt.date should not throw.

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-514.26.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 4.0.2
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.12
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.15
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@mroeschke

This comment has been minimized.

Copy link
Member

commented Dec 24, 2018

Happens specifically when inplace=True

In [8]: z = pd.Series(pd.date_range('2018-01-01', periods=7))
   ...: z = z.drop(z[z.dt.weekday >= 4].index)

In [9]: z.dt.date
Out[9]:
0    2018-01-01
1    2018-01-02
2    2018-01-03
3    2018-01-04
dtype: object

In [10]: z = pd.Series(pd.date_range('2018-01-01', periods=7))
    ...: z.drop(z[z.dt.weekday >= 4].index, inplace=True)

In [11]: z.dt.date
ValueError: Length of passed values is 4, index implies 7

@mroeschke mroeschke changed the title BUG: Series.dt accessor throws exception after Series.drop BUG: Series.dt accessor throws exception after Series.drop when inplace=True Dec 24, 2018

@jreback jreback added this to the 0.24.0 milestone Dec 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.