pastas / pastastore

:spaghetti: :convenience_store: Tools for managing timeseries and Pastas models
https://pastastore.readthedocs.io
MIT License
15 stars 4 forks source link

JSON can't handle datetime.datetime in pastastore metadata #52

Closed martinvonk closed 2 years ago

martinvonk commented 2 years ago

datetime in a dictionary can't be saved when writing the pastastore to a zip file. You get the following error: TypeError: Object of type datetime is not JSON serializable and the .zip file becomes empty.

This could be solved by checking if there are datetime.datetime formats in the metadata when adding a stress/oseries. pandas.to_datetime() should work or just convert to a string.

dbrakenhoff commented 2 years ago

I think we should add a method similar to pastastore.util.validate_names() that runs through the dtypes of dictionary values and checks whether Pastas supports writing those to JSON.

dbrakenhoff commented 2 years ago

I believe I added support for storing datetime.datetime entries in metadata in https://github.com/pastas/pastas/commit/99ca82ef87ec6aaacac225b3cfec646924d744c2.

@martinvonk, could you check if this is fixed now?

Note that the datetime entry will be converted to pastas.Timestamp on load.

martinvonk commented 2 years ago

Yes this is fixed now. Thanks for the heads up. I'll close the issue.