Skip to content

Commit 5ff1e19

Browse files
simplify wkb conversion
1 parent 8973490 commit 5ff1e19

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

climada/entity/exposures/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,10 +1132,8 @@ def write_hdf5(self, file_name):
11321132
"""
11331133
LOGGER.info("Writing %s", file_name)
11341134
store = pd.HDFStore(file_name, mode="w")
1135-
pandas_df = pd.DataFrame(self.gdf)
11361135
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()
1136+
pandas_df = self.data.to_wkb()
11391137

11401138
# Avoid pandas PerformanceWarning when writing HDF5 data
11411139
with warnings.catch_warnings():

climada/entity/exposures/test/test_base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ def test_io_hdf5_pass(self):
384384
exp.ref_year = 2020
385385
exp.value_unit = "XSD"
386386

387+
# add another geometry column
388+
exp.data["geocol2"] = exp.data.geometry.copy(deep=True)
389+
387390
file_name = DATA_DIR.joinpath("test_hdf5_exp.h5")
388391

389392
# pd.errors.PerformanceWarning should be suppressed. Therefore, make sure that
@@ -431,7 +434,12 @@ def test_io_hdf5_pass(self):
431434
u_coord.equal_crs(exp.crs, exp_read.crs),
432435
f"{exp.crs} and {exp_read.crs} are different",
433436
)
434-
self.assertTrue(u_coord.equal_crs(exp.gdf.crs, exp_read.gdf.crs))
437+
self.assertTrue(u_coord.equal_crs(exp.data.crs, exp_read.data.crs))
438+
439+
self.assertTrue(exp_read.data["geocol2"].dtype == "geometry")
440+
np.testing.assert_array_equal(
441+
exp.data["geocol2"].geometry, exp_read.data["geocol2"].values
442+
)
435443

436444

437445
class TestAddSea(unittest.TestCase):

0 commit comments

Comments
 (0)