From 0389fb187fc905af2e4ce6560b739c22813b71bc Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:11:40 +0100 Subject: [PATCH] Fix cbook style - add missing functions to cbook.pyi - PEP8 format conform test --- lib/matplotlib/cbook.pyi | 3 +++ lib/matplotlib/tests/test_cbook.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/cbook.pyi b/lib/matplotlib/cbook.pyi index 832a8003bdcf..f72fc4f615ad 100644 --- a/lib/matplotlib/cbook.pyi +++ b/lib/matplotlib/cbook.pyi @@ -181,4 +181,7 @@ def _setup_new_guiapp() -> None: ... def _format_approx(number: float, precision: int) -> str: ... def _g_sig_digits(value: float, delta: float) -> int: ... def _unikey_or_keysym_to_mplkey(unikey: str, keysym: str) -> str: ... +def _is_torch_array(x: Any) -> bool: ... +def _is_jax_array(x: Any) -> bool: ... +def _unpack_to_numpy(x: Any) -> Any: ... def _auto_format_str(fmt: str, value: Any) -> str: ... diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py index 938655507c2f..ec9352d369c4 100644 --- a/lib/matplotlib/tests/test_cbook.py +++ b/lib/matplotlib/tests/test_cbook.py @@ -943,13 +943,18 @@ def test_auto_format_str(fmt, value, result): def test_unpack_to_numpy_from_torch(): - # Test that torch tensors are converted to NumPy arrays. - # We don't want to create a dependency on torch in the test suite, so we mock it. + """ + Test that torch tensors are converted to NumPy arrays. + + We don't want to create a dependency on torch in the test suite, so we mock it. + """ class Tensor: def __init__(self, data): self.data = data + def __array__(self): return self.data + torch = ModuleType('torch') torch.Tensor = Tensor sys.modules['torch'] = torch @@ -962,11 +967,15 @@ def __array__(self): def test_unpack_to_numpy_from_jax(): - # Test that jax arrays are converted to NumPy arrays. - # We don't want to create a dependency on jax in the test suite, so we mock it. + """ + Test that jax arrays are converted to NumPy arrays. + + We don't want to create a dependency on jax in the test suite, so we mock it. + """ class Array: def __init__(self, data): self.data = data + def __array__(self): return self.data