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
{{ message }}
Repository navigation
Matplotlib >= v3.3.3 breaks with pandas.plotting.register_matplotlib_converters(), ax.pcolormesh(), and datetime objects #19871
Matplotlib >= v3.3.3 breaks when using pandas.plotting.register_matplotlib_converters(), ax.pcolormesh(), and and array of datetime.datetime() objects as coordinates.
Code was tested using clean conda environments only differing by Matplotlib version. Versions tested:
mpl v3.3.2: Code works
mpl v3.3.3: Code breaks
mpl v3.4.1: Code breaks
Code for reproduction
The code below will work if the following lines are commented/removed:
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
#!/usr/bin/env python3
from matplotlib import pyplot as plt
import numpy as np
import datetime
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
fig = plt.figure()
ax = fig.add_subplot(111)
times = [datetime.datetime(2021,1,1)]
while len(times) < 721:
times.append(times[-1]+datetime.timedelta(seconds=120))
y_vals = np.arange(101)
time_axis, y_axis = np.meshgrid(times,y_vals)
shape = (len(y_vals)-1,len(times)-1)
z_data = np.arange(shape[0]*shape[1])
z_data.shape = shape
im = ax.pcolormesh(time_axis, y_axis, z_data)
fig.savefig('bug_report.png')
Actual outcome
This traceback comes from my Matplotlib 3.4.1 conda environment:
Traceback (most recent call last):
File "./bug_report.py", line 23, in <module>
im = ax.pcolormesh(time_axis, y_axis, z_data)
File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/__init__.py", line 1352, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 6163, in pcolormesh
shading=shading, kwargs=kwargs)
File "/home/w2naf/anaconda3/envs/mpl3.4.1/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5655, in _pcolorargs
Nx = X.shape[-1]
AttributeError: 'list' object has no attribute 'shape'
This traceback comes from my Matplotlib 3.3.3 conda environment:
Traceback (most recent call last):
File "./bug_report.py", line 23, in <module>
im = ax.pcolormesh(time_axis, y_axis, z_data)
File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1447, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 6093, in pcolormesh
shading=shading, kwargs=kwargs)
File "/home/w2naf/anaconda3/envs/mpl3.3.3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5590, in _pcolorargs
Nx = X.shape[-1]
AttributeError: 'list' object has no attribute 'shape'
Expected outcome
Output from my Matplotlib 3.3.2 conda environment:
Matplotlib version
Operating system: Ubuntu 18.04.5 LTS
Matplotlib version: Code breaks in v3.3.3 and v3.4.1; Code works in v3.3.2
Matplotlib backend: Qt5Agg
Python version: 3.7.7
Other libraries: Pandas v1.2.3
Matplotlib and python were installed with Anaconda for Linux 64 Bit. (conda 4.9.2)
I think this would be more appropriately reported to pandas? We don't maintain matplotlib_converters, and we don't claim they will work. I'm going to close, but feel free to ask for a re-open if there is an identifiable bug on our side.
I agree the fix for this is probably on the pandas side, but given that this breaks on a patch release we should track down why we got less defensive about the return values from the converters and if that was intended or not.
The pandas unit converter returns a list from convert instead of a numpy array. If we should be more permissive, I'm not sure where or what the architecture for convert is supposed to be, if it doesn't return a numpy array. But I'm not sure if we specify what convert should do anywhere.
Activity
jklymak commentedon Apr 5, 2021
I think this would be more appropriately reported to pandas? We don't maintain
matplotlib_converters, and we don't claim they will work. I'm going to close, but feel free to ask for a re-open if there is an identifiable bug on our side.tacaswell commentedon Apr 5, 2021
I agree the fix for this is probably on the pandas side, but given that this breaks on a patch release we should track down why we got less defensive about the return values from the converters and if that was intended or not.
jklymak commentedon Apr 5, 2021
It is e602b0c #18549.
jklymak commentedon Apr 5, 2021
The pandas unit converter returns a list from
convertinstead of a numpy array. If we should be more permissive, I'm not sure where or what the architecture forconvertis supposed to be, if it doesn't return a numpy array. But I'm not sure if we specify whatconvertshould do anywhere.w2naf commentedon Apr 6, 2021
Do you still want me to file a pandas bug report, or wait until we have things more resolved here?
FIX: re-order unit conversion and mask array coercion
tacaswell commentedon May 5, 2021
@w2naf Yes, please report a bug with pandas.
FIX: re-order unit conversion and mask array coercion
FIX: re-order unit conversion and mask array coercion