Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a71c8ae

Browse files
authored
Merge pull request #19876 from tacaswell/fix_pandas_pcolor_regression
FIX: re-order unit conversion and mask array coercion
2 parents 564d4fd + 4f23d61 commit a71c8ae

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5621,9 +5621,10 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
56215621
if len(args) == 3:
56225622
# Check x and y for bad data...
56235623
C = np.asanyarray(args[2])
5624-
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
56255624
# unit conversion allows e.g. datetime objects as axis values
5625+
X, Y = args[:2]
56265626
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
5627+
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]
56275628

56285629
if funcname == 'pcolormesh':
56295630
if np.ma.is_masked(X) or np.ma.is_masked(Y):

lib/matplotlib/tests/test_axes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,36 @@ def test_boxplot_dates_pandas(pd):
16571657
plt.boxplot(data, positions=years)
16581658

16591659

1660+
def test_pcolor_regression(pd):
1661+
from pandas.plotting import (
1662+
register_matplotlib_converters,
1663+
deregister_matplotlib_converters,
1664+
)
1665+
1666+
fig = plt.figure()
1667+
ax = fig.add_subplot(111)
1668+
1669+
times = [datetime.datetime(2021, 1, 1)]
1670+
while len(times) < 7:
1671+
times.append(times[-1] + datetime.timedelta(seconds=120))
1672+
1673+
y_vals = np.arange(5)
1674+
1675+
time_axis, y_axis = np.meshgrid(times, y_vals)
1676+
shape = (len(y_vals) - 1, len(times) - 1)
1677+
z_data = np.arange(shape[0] * shape[1])
1678+
1679+
z_data.shape = shape
1680+
try:
1681+
register_matplotlib_converters()
1682+
1683+
im = ax.pcolormesh(time_axis, y_axis, z_data)
1684+
# make sure this does not raise!
1685+
fig.canvas.draw()
1686+
finally:
1687+
deregister_matplotlib_converters()
1688+
1689+
16601690
def test_bar_pandas(pd):
16611691
# Smoke test for pandas
16621692
df = pd.DataFrame(

0 commit comments

Comments
 (0)