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

ValueError raised when plottting reversed fixed-frequency TimedeltaIndex #37454

Closed
theavey opened this issue Oct 27, 2020 · 0 comments · Fixed by #37469
Closed

ValueError raised when plottting reversed fixed-frequency TimedeltaIndex #37454

theavey opened this issue Oct 27, 2020 · 0 comments · Fixed by #37469
Labels
Milestone

Comments

@theavey
Copy link
Contributor

theavey commented Oct 27, 2020

When plotting with a TimedeltaIndex with a fixed frequency and xmin > xmax, a ValueError gets raised.

>>> pd.Series([1,2], index=pd.timedelta_range(start=0, periods=2, freq='D')).plot(xlim=(3, 1))

C:\ProgramData\Miniconda3\envs\env_name\lib\site-packages\pandas\plotting_matplotlib\converter.py in call(self, x, pos)
1066 def call(self, x, pos=0) -> str:
1067 (vmin, vmax) = tuple(self.axis.get_view_interval())
-> 1068 n_decimals = int(np.ceil(np.log10(100 * 1e9 / (vmax - vmin))))
1069 if n_decimals > 9:
1070 n_decimals = 9

ValueError: cannot convert float NaN to integer

Seems that there should just be an abs in this line.

I would expect this to be able to output a plot successfully.

Works fine with a TimedeltaIndex with freq=None:

pd.Series([1,2], index=[pd.Timedelta(days=1), pd.Timedelta(days=2)]).plot(xlim=(3, 1))

INSTALLED VERSIONS

commit : db08276
python : 3.8.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20201009
Cython : None
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
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.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : 1.3.20
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants