Cannot serialize numpy.float32
See original GitHub issueHi,
I have an issue serialising a model that was fit with a column of type float32.
Version: fbprophet == 0.7.1 pystan == 2.19.1.1
Example code:
import pandas as pd
import numpy as np
from fbprophet import Prophet
from fbprophet.serialize import model_to_json
df = pd.DataFrame()
df["ds"] = pd.date_range(start="2020-01-01", end="2021-01-01", freq="1MS")
df["y"] = np.random.rand(df.shape[0])
df["y"] = df["y"].astype("float32")
model = Prophet()
model.fit(df)
model_json = model_to_json(model)
I did a bit of investigation:
# after returning the model_json before serialization:
import json
for key in model_json:
try:
json.dumps(model_json[key])
except TypeError:
print(key)
This returns only y_scale
and type(model_json["y_scale"]) => numpy.float32
.
Within serialize.py y_scale
is in the list SIMPLE_ATTRIBUTES
, as such it is serialised directly rather than using np.to_list()
This may relate to pull request #1656 and issue #1701
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
jsonify() can't serialize numpy.float32() · Issue #4012 - GitHub
Flask version: 1.1.2. The following code throws error - TypeError: Object of type float32 is not JSON serializable. x = {'value': numpy.float32 ...
Read more >numpy.float64 is JSON serializable but numpy.float32 is not
This led to the realization that the JSON module in Python can't serialize NumPy 32-bit floats. import numpy as np import json #...
Read more >TypeError: Object of type 'float32' is not JSON serializable
I'm working with numpy.float32 numbers and they don't go into JSON . What's the right approach to overcome this issue? import numpy ...
Read more >TypeError: Object of type float32 is not JSON serializable
The Python "TypeError: Object of type float32 is not JSON serializable" occurs when we try to convert a numpy float32 object to a...
Read more >list is not json serializable - casavacanzelescuderie.it
To solve the error, convert the numpy float to a Python float before ... I wrote a serialize query but it doesnt work....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes! that’s the problem. I’m on Pandas 1.2.0 and I’m getting the .max() as a numpy type:
I think your commit will solve it.
This fix has been pushed to pypi in the new v1.0 release.