Skip to content

Fix _is_tensorflow_array. #30114

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
May 29, 2025
Merged

Fix _is_tensorflow_array. #30114

merged 1 commit into from
May 29, 2025

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 27, 2025

The previous implementation was clearly wrong (the isinstance check would raise TypeError as the second argument would be a bool), but the tests didn't catch that because the bug led to _is_tensorflow_array returning False, then _unpack_to_numpy returning the original input, and then assert_array_equal implicitly converting result by calling __array__ on it. Fix the test by explicitly checking that result is indeed a numpy array, and also fix _is_tensorflow_array with more restrictive exception catching (also applied to _is_torch_array, _is_jax_array, and _is_pandas_dataframe, while we're at it).

PR summary

PR checklist

The previous implementation was clearly wrong (the isinstance check
would raise TypeError as the second argument would be a bool), but the
tests didn't catch that because the bug led to _is_tensorflow_array
returning False, then _unpack_to_numpy returning the original input,
and then assert_array_equal implicitly converting `result` by calling
`__array__` on it.  Fix the test by explicitly checking that `result`
is indeed a numpy array, and also fix _is_tensorflow_array with more
restrictive exception catching (also applied to _is_torch_array,
_is_jax_array, and _is_pandas_dataframe, while we're at it).
@anntzer anntzer added this to the v3.10.4 milestone May 27, 2025
@oscargus oscargus merged commit 42f1905 into matplotlib:main May 29, 2025
39 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 29, 2025
@anntzer anntzer deleted the ita branch May 29, 2025 15:33
oscargus pushed a commit that referenced this pull request May 31, 2025
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants