8000 Improve check for bbox by oscargus · Pull Request #27514 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Improve check for bbox #27514

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 3 commits into from
Dec 20, 2023
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/27514-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Exception when not passing a Bbox to BboxTransform*-classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The exception when not passing a Bbox to BboxTransform*-classes that expect one, e.g.,
`~matplotlib.transforms.BboxTransform` has changed from ``ValueError`` to ``TypeError``.
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations/27514-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``TransformNode.is_bbox``
~~~~~~~~~~~~~~~~~~~~~~~~~

... is deprecated. Instead check the object using ``isinstance(..., BboxBase)``.
20 changes: 7 additions & 13 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TransformNode:
# Some metadata about the transform, used to determine whether an
# invalidation is affine-only
is_affine = False
is_bbox = False
is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: False))

pass_through = False
"""
Expand Down Expand Up @@ -220,7 +220,7 @@ class BboxBase(TransformNode):
and height, but these are not stored explicitly.
"""

is_bbox = True
is_bbox = _api.deprecated("3.9")(_api.classproperty(lambda cls: True))
is_affine = True

if DEBUG:
Expand Down Expand Up @@ -1101,8 +1101,7 @@ def __init__(self, bbox, transform, **kwargs):
bbox : `Bbox`
transform : `Transform`
"""
if not bbox.is_bbox:
raise ValueError("'bbox' is not a bbox")
_api.check_isinstance(BboxBase, bbox=bbox)
_api.check_isinstance(Transform, transform=transform)
if transform.input_dims != 2 or transform.output_dims != 2:
raise ValueError(
Expand Down Expand Up @@ -1190,9 +1189,7 @@ def __init__(self, bbox, x0=None, y0=None, x1=None, y1=None, **kwargs):
The locked value for y1, or None to leave unlocked.

"""
if not bbox.is_bbox:
raise ValueError("'bbox' is not a bbox")

_api.check_isinstance(BboxBase, bbox=bbox)
super().__init__(**kwargs)
self._bbox = bbox
self.set_children(bbox)
Expand Down Expand Up @@ -2547,8 +2544,7 @@ def __init__(self, boxin, boxout, **kwargs):
Create a new `BboxTransform` that linearly transforms
points from *boxin* to *boxout*.
"""
if not boxin.is_bbox or not boxout.is_bbox:
raise ValueError("'boxin' and 'boxout' must be bbox")
_api.check_isinstance(BboxBase, boxin=boxin, boxout=boxout)

super().__init__(**kwargs)
self._boxin = boxin
Expand Down Expand Up @@ -2591,8 +2587,7 @@ def __init__(self, boxout, **kwargs):
Create a new `BboxTransformTo` that linearly transforms
points from the unit bounding box to *boxout*.
"""
if not boxout.is_bbox:
raise ValueError("'boxout' must be bbox")
_api.check_isinstance(BboxBase, boxout=boxout)

super().__init__(**kwargs)
self._boxout = boxout
Expand Down Expand Up @@ -2645,8 +2640,7 @@ class BboxTransformFrom(Affine2DBase):
is_separable = True

def __init__(self, boxin, **kwargs):
if not boxin.is_bbox:
raise ValueError("'boxin' must be bbox")
_api.check_isinstance(BboxBase, boxin=boxin)

super().__init__(**kwargs)
self._boxin = boxin
Expand Down
0