Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check crs attribute on GDF if no geo is present #566

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion climada/entity/exposures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,9 @@ def concat(exposures_list):
]
crss = [
ex.crs for ex in exposures_list
if isinstance(ex, (Exposures, GeoDataFrame)) and not ex.crs is None
if isinstance(ex, (Exposures, GeoDataFrame))
and hasattr(ex, "crs")
and ex.crs is not None
]
if crss:
crs = crss[0]
Expand Down
4 changes: 2 additions & 2 deletions climada/entity/exposures/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def test_set_gdf(self):
probe.set_gdf(empty_gdf)
self.assertTrue(probe.gdf.equals(gpd.GeoDataFrame()))
self.assertTrue(u_coord.equal_crs(DEF_CRS, probe.crs))
self.assertIsNone(probe.gdf.crs)
self.assertFalse(hasattr(probe.gdf, "crs"))

probe.set_gdf(gdf_with_geometry)
self.assertTrue(probe.gdf.equals(gdf_with_geometry))
Expand All @@ -457,7 +457,7 @@ def test_set_gdf(self):
probe.set_gdf(gdf_without_geometry)
self.assertTrue(probe.gdf.equals(good_exposures().gdf))
self.assertTrue(u_coord.equal_crs(DEF_CRS, probe.crs))
self.assertIsNone(probe.gdf.crs)
self.assertFalse(hasattr(probe.gdf, "crs"))

def test_set_crs(self):
"""Test setting the CRS"""
Expand Down
3 changes: 2 additions & 1 deletion climada/entity/measures/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def test_filter_exposures_pass(self):
self.assertEqual(res_exp.tag.file_name, exp.tag.file_name)
self.assertEqual(res_exp.tag.description, exp.tag.description)
self.assertTrue(u_coord.equal_crs(res_exp.crs, exp.crs))
self.assertTrue(u_coord.equal_crs(res_exp.gdf.crs, exp.gdf.crs))
self.assertFalse(hasattr(exp.gdf, "crs"))
self.assertFalse(hasattr(res_exp.gdf, "crs"))

# regions (that is just input data, no need for testing, but it makes the changed and unchanged parts obious)
self.assertTrue(np.array_equal(res_exp.gdf.region_id.values[0], 4))
Expand Down
2 changes: 1 addition & 1 deletion climada/util/test/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ def test_points_to_raster_pass(self):
df_val['value'] = np.ones(len(df_val)) * 10
crs = 'epsg:2202'
_raster, meta = u_coord.points_to_raster(df_val, val_names=['value'], crs=crs)
self.assertIsNone(df_val.crs) # points_to_raster must not modify df_val
self.assertFalse(hasattr(df_val, "crs")) # points_to_raster must not modify df_val
self.assertTrue(u_coord.equal_crs(meta['crs'], crs))
self.assertAlmostEqual(meta['transform'][0], 0.5)
self.assertAlmostEqual(meta['transform'][1], 0)
Expand Down