-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
timezone aware datetime64 object converter fails when plot #22859
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
xref #22790 doesn't seem to be in that output, so likely untested. Any help debugging / writing a failing unittest would be appreciated. |
Pandas also does not support |
Here's a nice, neat reproduction of the problem with a one-line hack that magically fixes it. Uncomment hack to see the fix. import pandas
import dateutil.parser
import datetime
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
start = dateutil.parser.parse("2018-05-17 19:00:00").replace(tzinfo=datetime.timezone.utc)
end = dateutil.parser.parse("2018-05-17 20:00:00").replace(tzinfo=datetime.timezone.utc)
df = pandas.DataFrame(data=[start, end], index=[0,1], columns=['x'])
# *** HACK: CONVERT datetime column to string and back again - who knows why this works? ***
# df['x'] = pandas.to_datetime(df['x'].astype(str))
print(df)
print(df.dtypes)
plt.plot(df['x'], [0,1], '--o') Here's my local versions I could repro this issue on:
|
@medlin01GA your timezone types are different In [30]: type(pandas.to_datetime(df['x'].astype(str))[0].tz)
Out[30]: pytz.UTC
In [31]: type(df.x[0].tz)
Out[31]: datetime.timezone You might want to try again once |
This is happening to me as well after I upgraded from Ubuntu 18.10 to 19.04. Before my code was running and now I also get: |
this issue might also be solved already, tried in pandas 0.25 @mroeschke @TomAugspurger probably this issue can be closed. |
Yes I think #27367 closed this. |
* Move the plot into its own Python file for faster iteration. * Switch the x-axis from ordinal dates to datetime objects, to dodge a breaking change in matplotlib: its default epoch for floating point days moved from the year AD 1 to the year AD 1970. * Upgrade Pandas to 1.0.0 to avoid: matplotlib/matplotlib#12310 pandas-dev/pandas#22859 * Switch to relying on `message` to determine if SGP4 failed. * Spruce up the axis labelling, just for fun. * Use the same plot in both places it’s discussed in the docs.
Code Sample, a copy-pastable example if possible
Problem description
Pandas converter, use to extract date
str
for axis labels, fails when index is timezone aware. This happends only if matplotlib>=3.0.0 version is installed. I reported the bug first to matplotlib (matplotlib/matplotlib#12310), but the close it as they believe that the bug is in pandas converter.Output of
pd.show_versions()
pandas: 0.23.4
pytest: None
pip: 18.0
setuptools: 40.4.3
Cython: None
numpy: 1.15.2
scipy: None
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: