Skip to content

Commit

Permalink
Merge pull request #20180 from meeseeksmachine/auto-backport-of-pr-19…
Browse files Browse the repository at this point in the history
…876-on-v3.4.x

Backport PR #19876 on branch v3.4.x (FIX: re-order unit conversion and mask array coercion)
  • Loading branch information
QuLogic committed May 7, 2021
2 parents 09dfa2e + 1dee4a6 commit 46343dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5651,9 +5651,10 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
if len(args) == 3:
# Check x and y for bad data...
C = np.asanyarray(args[2])
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
# unit conversion allows e.g. datetime objects as axis values
X, Y = args[:2]
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]

if funcname == 'pcolormesh':
if np.ma.is_masked(X) or np.ma.is_masked(Y):
Expand Down
30 changes: 30 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,36 @@ def test_boxplot_dates_pandas(pd):
plt.boxplot(data, positions=years)


def test_pcolor_regression(pd):
from pandas.plotting import (
register_matplotlib_converters,
deregister_matplotlib_converters,
)

fig = plt.figure()
ax = fig.add_subplot(111)

times = [datetime.datetime(2021, 1, 1)]
while len(times) < 7:
times.append(times[-1] + datetime.timedelta(seconds=120))

y_vals = np.arange(5)

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
try:
register_matplotlib_converters()

im = ax.pcolormesh(time_axis, y_axis, z_data)
# make sure this does not raise!
fig.canvas.draw()
finally:
deregister_matplotlib_converters()


def test_bar_pandas(pd):
# Smoke test for pandas
df = pd.DataFrame(
Expand Down

0 comments on commit 46343dc

Please sign in to comment.