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
# Case 1 - no error raised:df=pd.DataFrame({"col1":[1,2,3]})
ax=df.plot()
df[df["col1"]==9].plot(ax=ax)
# Case 2 - error raised:df=pd.DataFrame({"col1":[1,2,3]}, index=pd.date_range("2020-01-01 00:00:00", periods=3, freq="10s"))
ax=df.plot()
df[df["col1"]==9].plot(ax=ax)
Problem description
IndexError is raised when trying to plot an empty subset of a dataframe that has a DatetimeIndex to an already existing axis (case 2). The better option would be that no error is raised and simply nothing is added to the existing axis as is the case if the index is a normal index instead of a DatetimeIndex (case 1). This is better becaue it allows to plot subsets of a dataframe within a loop or similar without having to care about whether the resulting subset is gonna be empty or not.
Expected Output
When adding an empty subset of a dataframe with DatetimeIndex to an existing axis, nothing is added to the plot and no error is raised.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : 7d32926
python : 3.7.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
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
IndexError is raised when trying to plot an empty subset of a dataframe that has a DatetimeIndex to an already existing axis (case 2). The better option would be that no error is raised and simply nothing is added to the existing axis as is the case if the index is a normal index instead of a DatetimeIndex (case 1). This is better becaue it allows to plot subsets of a dataframe within a loop or similar without having to care about whether the resulting subset is gonna be empty or not.
Expected Output
When adding an empty subset of a dataframe with DatetimeIndex to an existing axis, nothing is added to the plot and no error is raised.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 7d32926
python : 3.7.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.2.2
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 21.0
setuptools : 49.6.0.post20210108
Cython : None
pytest : None
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.0
sqlalchemy : 1.3.20
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: