From 16629b6ea5114fa26cda778d4ff07097bf6f8e23 Mon Sep 17 00:00:00 2001 From: fjosw Date: Fri, 10 Mar 2023 14:18:21 +0000 Subject: [PATCH] Documentation updated --- docs/pyerrors/input/pandas.html | 72 +++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/docs/pyerrors/input/pandas.html b/docs/pyerrors/input/pandas.html index 6e74627c..18155e8f 100644 --- a/docs/pyerrors/input/pandas.html +++ b/docs/pyerrors/input/pandas.html @@ -222,38 +222,48 @@ 135 """ 136 out = df.copy() 137 for column in out: -138 if isinstance(out[column][0], (Obs, Corr)): -139 out[column] = out[column].transform(lambda x: create_json_string(x, indent=0)) -140 if gz is True: -141 out[column] = out[column].transform(lambda x: gzip.compress(x.encode('utf-8'))) -142 return out -143 +138 serialize = False +139 if isinstance(out[column][0], (Obs, Corr)): +140 serialize = True +141 elif isinstance(out[column][0], list): +142 if all(isinstance(o, Obs) for o in out[column][0]): +143 serialize = True 144 -145def _deserialize_df(df, auto_gamma=False): -146 """Deserializes all pyerrors json strings into Obs or Corr objects according to the pyerrors json specification. -147 -148 Parameters -149 ---------- -150 df : pandas.DataFrame -151 DataFrame to be deserilized. -152 auto_gamma : bool -153 If True applies the gamma_method to all imported Obs objects with the default parameters for -154 the error analysis. Default False. -155 -156 Notes: -157 ------ -158 In case any column of the DataFrame is gzipped it is gunzipped in the process. -159 """ -160 for column in df.select_dtypes(include="object"): -161 if isinstance(df[column][0], bytes): -162 if df[column][0].startswith(b"\x1f\x8b\x08\x00"): -163 df[column] = df[column].transform(lambda x: gzip.decompress(x).decode('utf-8')) -164 if isinstance(df[column][0], str): -165 if '"program":' in df[column][0][:20]: -166 df[column] = df[column].transform(lambda x: import_json_string(x, verbose=False)) -167 if auto_gamma is True: -168 df[column].apply(lambda x: x.gamma_method()) -169 return df +145 if serialize is True: +146 out[column] = out[column].transform(lambda x: create_json_string(x, indent=0)) +147 if gz is True: +148 out[column] = out[column].transform(lambda x: gzip.compress(x.encode('utf-8'))) +149 return out +150 +151 +152def _deserialize_df(df, auto_gamma=False): +153 """Deserializes all pyerrors json strings into Obs or Corr objects according to the pyerrors json specification. +154 +155 Parameters +156 ---------- +157 df : pandas.DataFrame +158 DataFrame to be deserilized. +159 auto_gamma : bool +160 If True applies the gamma_method to all imported Obs objects with the default parameters for +161 the error analysis. Default False. +162 +163 Notes: +164 ------ +165 In case any column of the DataFrame is gzipped it is gunzipped in the process. +166 """ +167 for column in df.select_dtypes(include="object"): +168 if isinstance(df[column][0], bytes): +169 if df[column][0].startswith(b"\x1f\x8b\x08\x00"): +170 df[column] = df[column].transform(lambda x: gzip.decompress(x).decode('utf-8')) +171 if isinstance(df[column][0], str): +172 if '"program":' in df[column][0][:20]: +173 df[column] = df[column].transform(lambda x: import_json_string(x, verbose=False)) +174 if auto_gamma is True: +175 if isinstance(df[column][0], list): +176 df[column].apply(lambda x: [o.gm() for o in x]) +177 else: +178 df[column].apply(lambda x: x.gamma_method()) +179 return df