-
Notifications
You must be signed in to change notification settings - Fork 39
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
plotting fails with numpy >= 2.0 #213
Comments
Just submitted PR. |
@harmsm - thanks for bringing this to my attention. I'm going to clean up some build issues, add a build for numpy 2, and accept the PR. Cheers, |
Thanks so much!
Mike
…On Tuesday, July 9th, 2024 at 08:22, Timothy M. Shead ***@***.***> wrote:
***@***.***(https://github.com/harmsm) - thanks for bringing this to my attention. I'm going to clean up some build issues, add a build for numpy 2, and accept the PR.
Cheers,
Tim
—
Reply to this email directly, [view it on GitHub](#213 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ABFZA6RWIDXJMPMVDOTL7BTZLPW2JAVCNFSM6AAAAABKKMIX6CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJXHA3TIMJUHE).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Graphs do not render when using numpy 2.0 because numpy changed the string representation of scalar values.
To reproduce
If I run the following code on my machine (toyplot 1.0.4-dev, Python 3.12, numpy 2.0, macOS Sonoma):
I get the following:
It's not just a problem with pdf rendering; the plot does not appear in a Jupyter notebook.
Root cause
This occurs because
repr(some_numpy_float)
now returns"np.float32(float_value)"
instead of"float_value"
. (See here for spec change). Throughout the code base, toyplot callsfloat(blah)
whereblah
is a string representation of a numpy float. This fails because values like"np.float(3.0)"
cannot be interpreted as floats.At first I thought the numpy-style strings were all arising in toyplot and that I could fix this by converting all
repr(value)
calls tostr(value)
calls. This solved some of the problems I observed; however, it looks like at least some of the numpy-style strings are coming from the standard xml library used to generate svg. This likely means toyplot will have to guard against injecting numpy-style strings into rendered output for the foreseeable future.One solution
I implemented one possible solution. I made two new functions:
toyplot.require.as_float
andtoyplot.require.as_int
. These functions are drop-in replacements forfloat(value)
andfloat(int)
that, upon failing a standard coercion, try to convert from a numpy string representation.The text was updated successfully, but these errors were encountered: