@@ -182,7 +182,7 @@ def test__init__mda_in_kwargs(self):
182182 def test_read_raster_pass (self ):
183183 """from_raster"""
184184 exp = Exposures .from_raster (
185- HAZ_DEMO_FL , window = Window (10 , 20 , 50 , 60 ), attrs = {"value_unit" : "USD " }
185+ HAZ_DEMO_FL , window = Window (10 , 20 , 50 , 60 ), attrs = {"value_unit" : "PKR " }
186186 )
187187 exp .check ()
188188 self .assertTrue (u_coord .equal_crs (exp .crs , DEF_CRS ))
@@ -204,7 +204,7 @@ def test_read_raster_pass(self):
204204 self .assertAlmostEqual (
205205 exp .gdf ["value" ].values .reshape ((60 , 50 ))[25 , 12 ], 0.056825936
206206 )
207- self .assertEqual (exp .value_unit , "USD " )
207+ self .assertEqual (exp .value_unit , "PKR " )
208208
209209 def test_assign_raster_pass (self ):
210210 """Test assign_centroids with raster hazard"""
@@ -429,16 +429,27 @@ def test_read_template_pass(self):
429429 exp_df = Exposures (df )
430430 # set metadata
431431 exp_df .ref_year = 2020
432- exp_df .value_unit = "XSD "
432+ exp_df .value_unit = "PAK "
433433 exp_df .check ()
434434
435+ def test_handling_unit_conflicts_pass (self ):
436+ """Check that the value_unit is correctly set when there are conflicting value_unit definitions in the data frame and the meta attribute."""
437+ df = pd .read_excel (ENT_TEMPLATE_XLS )
438+ exp_df = Exposures (df , meta = {"value_unit" : "XSD" }, value_unit = "XSD" )
439+ exp_df .check ()
440+ self .assertEqual (exp_df .value_unit , "XSD" )
441+ with self .assertRaises (ValueError ) as cm :
442+ exp_df = Exposures (df , meta = {"value_unit" : "XSD" }, value_unit = "PAK" )
443+ with self .assertRaises (ValueError ) as cm :
444+ exp_df = Exposures (df , meta = {"value_unit" : "PAK" }, value_unit = "XSD" )
445+ with self .assertRaises (ValueError ) as cm :
446+ exp_df = Exposures (df , meta = {"value_unit" : "PAK" }, value_unit = "PAK" )
447+
435448 def test_io_hdf5_pass (self ):
436449 """write and read hdf5"""
437- exp = Exposures (pd .read_excel (ENT_TEMPLATE_XLS ), crs = "epsg:32632" )
438-
439- # set metadata
440- exp .ref_year = 2020
441- exp .value_unit = "XSD"
450+ exp = Exposures (
451+ pd .read_excel (ENT_TEMPLATE_XLS ), crs = "epsg:32632" , ref_year = 2020
452+ )
442453
443454 # add another geometry column
444455 exp .data ["geocol2" ] = exp .data .geometry .copy (deep = True )
0 commit comments