pastas / pastastore

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

problems with float to int conversion when reading pastastore from zip #108

Closed OnnoEbbens closed 8 months ago

OnnoEbbens commented 9 months ago

I have a stress consisting of integers. To avoid any pastas validation errors I convert the stress from integers to floats before I add it to the pastastore. I save the pastastore to a .zip file and then I get an error when I try to read it from the .zip. When the stress is read from the zip file it is converted back from floats to integers which results in an error when validating the series in pastas.

to reproduce:

import pastastore as pst
import pandas as pd
df = pd.DataFrame(np.random.randint(0, 100, 100), index=pd.date_range('2000-1-1' ,periods=100))
# create PastaStore instance
pstore = pst.PastaStore(pst.DictConnector())

pstore.add_stress(df.astype(float), "evap", kind="evap", metadata={"x": 100_000, "y": 400_000})

pstore.to_zip('pstore.zip')
pstore_in = pst.PastaStore.from_zip("pstore.zip", conn=pst.DictConnector())
dbrakenhoff commented 9 months ago

Perhaps Pastas checking if the time series has dtype float is too harsh? If we also allow ints in the validate series function this problem would also be solved? But I'm okay with implementing your proposed fix here too.

dbrakenhoff commented 8 months ago

Fixed by #109