mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
Serialize list of Obs in pandas.to_sql (#162)
* feat: Added serialization of list of Obs in pandas.to_sql. * tests: test for list of Obs to sql added. * feat: auto_gamma functionality added for deserialization of lists of Obs.
This commit is contained in:
parent
a7a098b861
commit
3c942b380d
2 changed files with 23 additions and 1 deletions
|
@ -135,7 +135,14 @@ def _serialize_df(df, gz=False):
|
|||
"""
|
||||
out = df.copy()
|
||||
for column in out:
|
||||
serialize = False
|
||||
if isinstance(out[column][0], (Obs, Corr)):
|
||||
serialize = True
|
||||
elif isinstance(out[column][0], list):
|
||||
if all(isinstance(o, Obs) for o in out[column][0]):
|
||||
serialize = True
|
||||
|
||||
if serialize is True:
|
||||
out[column] = out[column].transform(lambda x: create_json_string(x, indent=0))
|
||||
if gz is True:
|
||||
out[column] = out[column].transform(lambda x: gzip.compress(x.encode('utf-8')))
|
||||
|
@ -165,5 +172,8 @@ def _deserialize_df(df, auto_gamma=False):
|
|||
if '"program":' in df[column][0][:20]:
|
||||
df[column] = df[column].transform(lambda x: import_json_string(x, verbose=False))
|
||||
if auto_gamma is True:
|
||||
df[column].apply(lambda x: x.gamma_method())
|
||||
if isinstance(df[column][0], list):
|
||||
df[column].apply(lambda x: [o.gm() for o in x])
|
||||
else:
|
||||
df[column].apply(lambda x: x.gamma_method())
|
||||
return df
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue