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

Skip to content

Commit 158ee50

Browse files
anntzertacaswell
authored andcommitted
FIX: if the first elements of an array are masked keep checking
closes #14356
1 parent 918b691 commit 158ee50

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/matplotlib/tests/test_units.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,14 @@ def test_jpl_barh_units():
153153
def test_empty_arrays():
154154
# Check that plotting an empty array with a dtype works
155155
plt.scatter(np.array([], dtype='datetime64[ns]'), np.array([]))
156+
157+
158+
def test_scatter_element0_masked():
159+
160+
times = np.arange('2005-02', '2005-03', dtype='datetime64[D]')
161+
162+
y = np.arange(len(times))
163+
y[0] = np.nan
164+
fig, ax = plt.subplots()
165+
ax.scatter(times, y)
166+
fig.canvas.draw()

lib/matplotlib/units.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def _is_natively_supported(x):
6464
if np.iterable(x):
6565
# Assume lists are homogeneous as other functions in unit system.
6666
for thisx in x:
67+
if thisx is ma.masked:
68+
continue
6769
return isinstance(thisx, Number) and not isinstance(thisx, Decimal)
6870
else:
6971
return isinstance(x, Number) and not isinstance(x, Decimal)
@@ -144,6 +146,8 @@ def is_numlike(x):
144146
"""
145147
if np.iterable(x):
146148
for thisx in x:
149+
if thisx is ma.masked:
150+
continue
147151
return isinstance(thisx, Number)
148152
else:
149153
return isinstance(x, Number)

0 commit comments

Comments
 (0)