BUG: Series.dt accessor throws exception after Series.drop when inplace=True · Issue #24408 · pandas-dev/pandas (original) (raw)
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