@@ -74,32 +74,39 @@ def test_convert_unit_ur_injection():
7474
7575def test_convert_unit_mapping ():
7676 start = create_test_df (
77- variables = [(f"variable_{ i } " , "Mt" ) for i in range (5 )],
78- n_scenarios = 3 ,
79- n_runs = 6 ,
80- timepoints = np .array ([1.0 , 2.0 , 3.0 ]),
77+ variables = [
78+ ("co2_emissions" , "Mt CO2/yr" ),
79+ ("erf" , "W / m^2" ),
80+ ("ohc" , "ZJ" ),
81+ ],
82+ n_scenarios = 2 ,
83+ n_runs = 2 ,
84+ timepoints = np .array ([1850.0 , 2000.0 , 2050.0 , 2100.0 ]),
8185 )
8286
8387 # Don't convert W / m^2
84- res = start . convert_unit ({"Mt CO2/yr" : "Gt C/yr" , "ZJ" : "J" })
88+ res = convert_unit (start , {"Mt CO2/yr" : "Gt C/yr" , "ZJ" : "J" })
8589
8690 np .testing .assert_equal (
87- res .iloc [0 , :].values ,
88- start .iloc [0 , :].values * 12.0 / 44000.0 ,
91+ res .loc [res .index .get_level_values ("variable" ) == "co2_emissions" , :].values ,
92+ 12.0
93+ / 44_000.0
94+ * start .loc [
95+ start .index .get_level_values ("variable" ) == "co2_emissions" , :
96+ ].values ,
8997 )
9098
9199 np .testing .assert_equal (
92- res .iloc [ 1 , :].values ,
93- start .iloc [ 1 , :].values ,
100+ res .loc [ res . index . get_level_values ( "variable" ) == "erf" , :].values ,
101+ start .loc [ start . index . get_level_values ( "variable" ) == "erf" , :].values ,
94102 )
95103
96104 np .testing .assert_equal (
97- res .iloc [ 2 , :].values ,
98- start .iloc [ 2 , :].values * 1e21 ,
105+ res .loc [ res . index . get_level_values ( "variable" ) == "ohc" , :].values ,
106+ 1e21 * start .loc [ start . index . get_level_values ( "variable" ) == "ohc" , :].values ,
99107 )
100108
101109
102- # - test error paths
103110def test_convert_unit_like ():
104111 start = create_test_df (
105112 variables = [(f"variable_{ i } " , "Mt" ) for i in range (5 )],
@@ -223,3 +230,8 @@ def test_convert_unit_like_different_unit_level_explicit_target_level():
223230 res .iloc [2 , :].values ,
224231 start .iloc [2 , :].values + 273.0 ,
225232 )
233+
234+
235+ # To write:
236+ # - no op i.e. what happens when df is already in the right units
237+ # - tests of various error paths
0 commit comments