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

Skip to content

Use _api.check_shape more. #21695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ def _create_lookup_table(N, data, gamma=1.0):
adata = np.array(data)
except Exception as err:
raise TypeError("data must be convertible to an array") from err
shape = adata.shape
if len(shape) != 2 or shape[1] != 3:
raise ValueError("data must be nx3 format")
_api.check_shape((None, 3), data=adata)

x = adata[:, 0]
y0 = adata[:, 1]
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,11 +1656,10 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
raise NotImplementedError('Only defined in 2D')
angles = np.asarray(angles)
pts = np.asarray(pts)
if angles.ndim != 1 or angles.shape[0] != pts.shape[0]:
raise ValueError("'angles' must be a column vector and have same "
"number of rows as 'pts'")
if pts.shape[1] != 2:
raise ValueError("'pts' must be array with 2 columns for x, y")
_api.check_shape((None, 2), pts=pts)
_api.check_shape((None,), angles=angles)
if len(angles) != len(pts):
raise ValueError("There must be as many 'angles' as 'pts'")
# Convert to radians if desired
if not radians:
angles = np.deg2rad(angles)
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/tri/triinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,7 @@ def _safe_inv22_vectorized(M):

*M* : array of (2, 2) matrices to inverse, shape (n, 2, 2)
"""
assert M.ndim == 3
assert M.shape[-2:] == (2, 2)
_api.check_shape((None, 2, 2), M=M)
M_inv = np.empty_like(M)
prod1 = M[:, 0, 0]*M[:, 1, 1]
delta = prod1 - M[:, 0, 1]*M[:, 1, 0]
Expand Down Expand Up @@ -1441,8 +1440,7 @@ def _pseudo_inv22sym_vectorized(M):

*M* : array of (2, 2) matrices to inverse, shape (n, 2, 2)
"""
assert M.ndim == 3
assert M.shape[-2:] == (2, 2)
_api.check_shape((None, 2, 2), M=M)
M_inv = np.empty_like(M)
prod1 = M[:, 0, 0]*M[:, 1, 1]
delta = prod1 - M[:, 0, 1]*M[:, 1, 0]
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,8 @@ def set_val(self, val):
----------
val : tuple or array-like of float
"""
val = np.sort(np.asanyarray(val))
if val.shape != (2,):
raise ValueError(
f"val must have shape (2,) but has shape {val.shape}"
)
val = np.sort(val)
_api.check_shape((2,), val=val)
val[0] = self._min_in_bounds(val[0])
val[1] = self._max_in_bounds(val[1])
xy = self.poly.xy
Expand Down
7 changes: 1 addition & 6 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,8 @@ def set_box_aspect(self, aspect, *, zoom=1):
if aspect is None:
aspect = np.asarray((4, 4, 3), dtype=float)
else:
orig_aspect = aspect
aspect = np.asarray(aspect, dtype=float)
if aspect.shape != (3,):
raise ValueError(
"You must pass a 3-tuple that can be cast to floats. "
f"You passed {orig_aspect!r}"
)
_api.check_shape((3,), aspect=aspect)
# default scale tuned to match the mpl32 appearance.
aspect *= 1.8294640721620434 * zoom / np.linalg.norm(aspect)

Expand Down