-
Notifications
You must be signed in to change notification settings - Fork 475
varLib.interpolatable --json with scipy installed: Object of type int64 is not JSON serializable #3522
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
Comments
I assume that the solution here would be, when So here:
You could do something like... json_encoder = None
try:
import scipy
import numpy
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, numpy.integer):
return int(obj)
if isinstance(obj, numpy.floating):
return float(obj)
if isinstance(obj, numpy.ndarray):
return obj.tolist()
return super(NumpyEncoder, self).default(obj)
json_encoder = NumpyEncoder
except ImportError:
pass
print(json.dumps(problems, cls=json_encoder), file=f) |
I can confirm that the above approach resolves the issue. Should I put together a PR? |
I think we want to convert back to regular Python types or whatever it is that the non-scipy path is using. Thanks for the report! |
Would be great if you can send a PR with the approach I suggested. |
Ah, yes, that would keep all the |
Hello.
It seems that, the moment I install
scipy
into my project,varLib.interpolatable
starts using it, and then fails outputting JSON with:TypeError: ('Object of type int64 is not JSON serializable')
To clarify, the above happens when running the following with
scipy
installed:I assume this may be due to some conditional
scipy
imports? E.g.:fonttools/Lib/fontTools/varLib/interpolatableHelpers.py
Lines 174 to 188 in 90fed08
fonttools/Lib/fontTools/varLib/interpolatableHelpers.py
Lines 306 to 308 in 90fed08
Happy to dig deeper, and maybe provide a minimal reproduction, with some guidance on how to best supply that?
Thank you :)
The text was updated successfully, but these errors were encountered: