From d3397dc8a4c59b41af73d156fab7d6617f0da46d Mon Sep 17 00:00:00 2001 From: SRDM Date: Wed, 26 Jun 2024 12:18:52 +0200 Subject: [PATCH 1/8] applying hooks to all dataframe columns --- pandapower/io_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index f22325e46..89f7b4109 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -577,11 +577,12 @@ def DataFrame(self): df.columns.names = column_names # recreate jsoned objects - for col in ('object', 'controller'): # "controller" for backwards compatibility - if (col in df.columns): - df[col] = df[col].apply(self.pp_hook) if 'geo' in df.columns: df['geo'] = df['geo'].dropna().apply(json.dumps).apply(geojson.loads) + dtp = df.dtypes + for col in df.columns: + df[col] = df[col].apply(self.pp_hook) + df = df.astype(dtype = dtp) return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, From b8704917e198502e77c0bf63fea3b9baa427a9cf Mon Sep 17 00:00:00 2001 From: SRDM Date: Thu, 27 Jun 2024 00:14:31 +0200 Subject: [PATCH 2/8] just using object types --- pandapower/io_utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 89f7b4109..6d8b41242 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -579,10 +579,12 @@ def DataFrame(self): # recreate jsoned objects if 'geo' in df.columns: df['geo'] = df['geo'].dropna().apply(json.dumps).apply(geojson.loads) - dtp = df.dtypes - for col in df.columns: + + df_obj = df.select_dtypes(include=['object']) + dtyp = df_obj.dtypes + for col in df_obj: df[col] = df[col].apply(self.pp_hook) - df = df.astype(dtype = dtp) + df[df_obj.columns] = df[df_obj.columns].astype(dtype = dtyp) return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, From 102015f0b93bf13ecaa32718bc8c75d8e06cb22e Mon Sep 17 00:00:00 2001 From: SRDM Date: Sun, 30 Jun 2024 17:11:05 +0200 Subject: [PATCH 3/8] in objects nan values are none --- pandapower/io_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 6d8b41242..0d7e60457 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -585,6 +585,7 @@ def DataFrame(self): for col in df_obj: df[col] = df[col].apply(self.pp_hook) df[df_obj.columns] = df[df_obj.columns].astype(dtype = dtyp) + df[df_obj.columns][pd.isnull(df_obj.columns)] = None return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, From 47149769856672328830fda6a28089c79df0749d Mon Sep 17 00:00:00 2001 From: SRDM Date: Sun, 30 Jun 2024 17:18:23 +0200 Subject: [PATCH 4/8] small bug --- pandapower/io_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 0d7e60457..157ffe0c9 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -585,7 +585,7 @@ def DataFrame(self): for col in df_obj: df[col] = df[col].apply(self.pp_hook) df[df_obj.columns] = df[df_obj.columns].astype(dtype = dtyp) - df[df_obj.columns][pd.isnull(df_obj.columns)] = None + df[df_obj.columns][pd.isnull(df[df_obj.columns])] = None return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, From 5fda170c17690c32388331161b52af40a882655c Mon Sep 17 00:00:00 2001 From: SRDM Date: Sun, 30 Jun 2024 17:53:45 +0200 Subject: [PATCH 5/8] different version as old version is not working --- pandapower/io_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 157ffe0c9..cf5082b7c 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -584,8 +584,8 @@ def DataFrame(self): dtyp = df_obj.dtypes for col in df_obj: df[col] = df[col].apply(self.pp_hook) + df[col][pd.isnull(df[col])] = None df[df_obj.columns] = df[df_obj.columns].astype(dtype = dtyp) - df[df_obj.columns][pd.isnull(df[df_obj.columns])] = None return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, From af7e9291441f44f15b0a6bfd7e6ce95046e5ae59 Mon Sep 17 00:00:00 2001 From: srdm Date: Tue, 20 Aug 2024 09:39:04 +0200 Subject: [PATCH 6/8] deprecating warnings --- pandapower/io_utils.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index c5d8d6af0..0241cb1bc 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -579,11 +579,10 @@ def DataFrame(self): df['geo'] = df['geo'].dropna().apply(json.dumps).apply(geojson.loads) df_obj = df.select_dtypes(include=['object']) - dtyp = df_obj.dtypes for col in df_obj: df[col] = df[col].apply(self.pp_hook) - df[col][pd.isnull(df[col])] = None - df[df_obj.columns] = df[df_obj.columns].astype(dtype = dtyp) + df[col] = df[col].astype(dtype = 'object') + df.loc[pd.isnull(df[col]), col] = None return df @from_serializable.register(class_name='pandapowerNet', module_name='pandapower.auxiliary')#, @@ -675,10 +674,6 @@ def GeoDataFrame(self): else: df.set_index(df.index.values.astype(numpy.int64), inplace=True) # coords column is not handled properly when using from_features - if 'coords' in df: - # df['coords'] = df.coords.apply(json.loads) - valid_coords = ~pd.isnull(df.coords) - df.loc[valid_coords, 'coords'] = df.loc[valid_coords, "coords"].apply(json.loads) df = df.reindex(columns=self.d['columns']) # df.astype changes geodataframe to dataframe -> _preserve_dtypes fixes it From 85f705d911707691f7fd1579f1eeca5076fe47cb Mon Sep 17 00:00:00 2001 From: srdm Date: Tue, 20 Aug 2024 09:40:58 +0200 Subject: [PATCH 7/8] revert change as handled in different PR --- pandapower/io_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 0241cb1bc..5b43e87a1 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -674,6 +674,10 @@ def GeoDataFrame(self): else: df.set_index(df.index.values.astype(numpy.int64), inplace=True) # coords column is not handled properly when using from_features + if 'coords' in df: + # df['coords'] = df.coords.apply(json.loads) + valid_coords = ~pd.isnull(df.coords) + df.loc[valid_coords, 'coords'] = df.loc[valid_coords, "coords"].apply(json.loads) df = df.reindex(columns=self.d['columns']) # df.astype changes geodataframe to dataframe -> _preserve_dtypes fixes it From 4c65d83483b978f0706a75a75b788659b755013d Mon Sep 17 00:00:00 2001 From: srdm Date: Tue, 7 Jan 2025 11:35:18 +0100 Subject: [PATCH 8/8] fix bug --- pandapower/io_utils.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pandapower/io_utils.py b/pandapower/io_utils.py index 9fb5d7622..75434c4a3 100644 --- a/pandapower/io_utils.py +++ b/pandapower/io_utils.py @@ -575,18 +575,14 @@ def DataFrame(self): if column_names is not None: df.columns.names = column_names - # recreate jsoned objects - for col in ('object', 'controller'): # "controller" for backwards compatibility - if (col in df.columns): - df[col] = df[col].apply(partial( - self.pp_hook, ignore_unknown_objects=self.ignore_unknown_objects - )) if 'geo' in df.columns: df['geo'] = df['geo'].dropna().apply(json.dumps).apply(geojson.loads) df_obj = df.select_dtypes(include=['object']) for col in df_obj: - df[col] = df[col].apply(self.pp_hook) + df[col] = df[col].apply(partial( + self.pp_hook, ignore_unknown_objects=self.ignore_unknown_objects + )) df[col] = df[col].astype(dtype = 'object') df.loc[pd.isnull(df[col]), col] = None return df