Skip to content

Commit 6bbedd4

Browse files
authored
Merge pull request #22736 from meeseeksmachine/auto-backport-of-pr-22719-on-v3.5.x
Backport PR #22719 on branch v3.5.x (Fix incorrect deprecation warning)
2 parents 7f6b0a1 + a49d527 commit 6bbedd4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/matplotlib/category.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def convert(value, unit, axis):
5858
is_numlike = all(units.ConversionInterface.is_numlike(v)
5959
and not isinstance(v, (str, bytes))
6060
for v in values)
61-
if is_numlike:
61+
if values.size and is_numlike:
6262
_api.warn_deprecated(
6363
"3.5", message="Support for passing numbers through unit "
6464
"converters is deprecated since %(since)s and support will be "
@@ -230,7 +230,7 @@ def update(self, data):
230230
convertible = self._str_is_convertible(val)
231231
if val not in self._mapping:
232232
self._mapping[val] = next(self._counter)
233-
if convertible:
233+
if data.size and convertible:
234234
_log.info('Using categorical units to plot a list of strings '
235235
'that are all parsable as floats or dates. If these '
236236
'strings should be plotted as numbers, cast to the '

lib/matplotlib/tests/test_category.py

+9
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ def test_overriding_units_in_plot(fig_test, fig_ref):
307307
assert y_units is ax.yaxis.units
308308

309309

310+
def test_no_deprecation_on_empty_data():
311+
"""
312+
Smoke test to check that no deprecation warning is emitted. See #22640.
313+
"""
314+
f, ax = plt.subplots()
315+
ax.xaxis.update_units(["a", "b"])
316+
ax.plot([], [])
317+
318+
310319
def test_hist():
311320
fig, ax = plt.subplots()
312321
n, bins, patches = ax.hist(['a', 'b', 'a', 'c', 'ff'])

0 commit comments

Comments
 (0)