Skip to content

Commit 8973490

Browse files
simplify wkb columns collection
1 parent 9312b30 commit 8973490

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

climada/entity/exposures/base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,9 @@ def write_hdf5(self, file_name):
11331133
LOGGER.info("Writing %s", file_name)
11341134
store = pd.HDFStore(file_name, mode="w")
11351135
pandas_df = pd.DataFrame(self.gdf)
1136-
wkb_columns = []
1137-
for col in pandas_df.columns:
1138-
if str(pandas_df[col].dtype) == "geometry":
1139-
pandas_df[col] = gpd.GeoSeries(pandas_df[col]).to_wkb()
1140-
wkb_columns.append(col)
1136+
geocols = self.gdf.columns[self.gdf.dtypes == "geometry"].to_list()
1137+
for col in geocols:
1138+
pandas_df[col] = gpd.GeoSeries(pandas_df[col]).to_wkb()
11411139

11421140
# Avoid pandas PerformanceWarning when writing HDF5 data
11431141
with warnings.catch_warnings():
@@ -1149,7 +1147,7 @@ def write_hdf5(self, file_name):
11491147
for var in type(self)._metadata:
11501148
var_meta[var] = getattr(self, var)
11511149
var_meta["crs"] = self.crs
1152-
var_meta["wkb_columns"] = wkb_columns
1150+
var_meta["wkb_columns"] = geocols
11531151
store.get_storer("exposures").attrs.metadata = var_meta
11541152

11551153
store.close()

0 commit comments

Comments
 (0)