-
Notifications
You must be signed in to change notification settings - Fork 358
-
Notifications
You must be signed in to change notification settings - Fork 358
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
PatchCollection - TypeError: array([ 1.]) is not JSON serializable #434
Comments
I was having a similar error. It seems Fix: class NumpyEncoder(json.JSONEncoder):
""" Special json encoder for numpy types """
def default(self, obj):
if isinstance(obj, (numpy.int_, numpy.intc, numpy.intp, numpy.int8,
numpy.int16, numpy.int32, numpy.int64, numpy.uint8,
numpy.uint16,numpy.uint32, numpy.uint64)):
return int(obj)
elif isinstance(obj, (numpy.float_, numpy.float16, numpy.float32,
numpy.float64)):
return float(obj)
elif isinstance(obj,(numpy.ndarray,)): #### This is the fix
return obj.tolist()
return json.JSONEncoder.default(self, obj) |
Thanks shouldsee! Your fix solved my save_html problem. I was getting "array is not JSON serializable html" when trying to save a scatter plot. |
It seems to me that this issue hasn't been solved in the latest release? I've got the latest version and had to fix it manually too. Thanks anyway @shouldsee ! |
I'll merge a pull request if someone creates one. Bonus points if the automatic tests all pass! |
Suggested fix also resolved my issue. |
Since javadba did not make a PR out of their commit I duplicated it. |
This is still an issue with I fix it manually by overwriting mpld3._display.NumpyEncoder in my program
|
Is there a production fix for this as yet? I introduced mpld3 into a Python project and am getting the same errors. Cheers! |
This fix should be resolved in master. There has not been a release of mpl3d in almost 2 years. i do not know when/if there will be another as it is not actively unmaintained... To use the mpld3 master branch or add |
@aflaxman @jakevdp perhaps it would be worth considering archiving this repository to indicate more clearly that the project is unmaintained: https://help.github.com/articles/archiving-a-github-repository/ I did this for |
@cliffckerr and company are planning to revive this project! if that has changed, i think archiving is a great idea. |
I have missed the days with mpld3+ Django. Not sure I will be of any help but please keep this alive!
…Sent from my iPhone
On 14 Jul 2018, at 00:01, Abraham Flaxman <notifications@github.com<mailto:notifications@github.com>> wrote:
@cliffckerr<https://github.com/cliffckerr> and company are planning to revive this project! if that has changed, i think archiving is a great idea.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#434 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AHqXbA3CO-1c_aiOuNnJMbFdUtE_5j1Eks5uGSaZgaJpZM4P4Xoe>.
|
Thanks all. I did not realise the code was unmaintained. It sounded perfect for my needs. |
@addinall @aflaxman @bryevdv We are indeed reviving it! We are currently working on our fork (https://github.com/optimamodel/mpld3) but once everything is stable we'll be merging back here. |
👍 |
Similar issue exists with fig_to_dict() as well. The returned dict cannot be serialized to json due to included ndarray unless right encoder is passed. One way to ovecome the issue is by using the internal NumpyEncoder class itself. For eg.
|
Thank you very much! |
Added serializer fix from mpld3#434.
I want to make a .html with a plot of some patches in a patch collection.
Im running the example from "https://matplotlib.org/examples/api/patch_collection.html"
Could someone please help?
thanks,
i get this error:
The text was updated successfully, but these errors were encountered: