Skip to content

Fix cbook style #27922

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
Mar 15, 2024
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
3 changes: 3 additions & 0 deletions lib/matplotlib/cbook.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
17 changes: 13 additions & 4 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down