Skip to content

Commit

Permalink
Merge pull request #26653 from meeseeksmachine/auto-backport-of-pr-26…
Browse files Browse the repository at this point in the history
…597-on-v3.7.x

Backport PR #26597 on branch v3.7.x (Squeeze post-converted values when validating limits)
  • Loading branch information
QuLogic committed Aug 31, 2023
2 parents 3c98167 + 815ab8a commit 69961d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3565,6 +3565,8 @@ def _validate_converted_limits(self, limit, convert):
"""
if limit is not None:
converted_limit = convert(limit)
if isinstance(converted_limit, np.ndarray):
converted_limit = converted_limit.squeeze()
if (isinstance(converted_limit, Real)
and not np.isfinite(converted_limit)):
raise ValueError("Axis limits cannot be NaN or Inf")
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Catch all for categorical functions"""
import warnings

import pytest
import numpy as np

Expand Down Expand Up @@ -309,3 +311,13 @@ def test_hist():
n, bins, patches = ax.hist(['a', 'b', 'a', 'c', 'ff'])
assert n.shape == (10,)
np.testing.assert_allclose(n, [2., 0., 0., 1., 0., 0., 1., 0., 0., 1.])


def test_set_lim():
# Numpy 1.25 deprecated casting [2.] to float, catch_warnings added to error
# with numpy 1.25 and prior to the change from gh-26597
# can be removed once the minimum numpy version has expired the warning
f, ax = plt.subplots()
ax.plot(["a", "b", "c", "d"], [1, 2, 3, 4])
with warnings.catch_warnings():
ax.set_xlim("b", "c")

0 comments on commit 69961d6

Please sign in to comment.