1111
1212import windpowerlib .wind_turbine as wt
1313import windpowerlib .modelchain as mc
14+ from windpowerlib .tools import WindpowerlibUserWarning
1415
1516
1617class TestModelChain :
1718 @classmethod
18- def setup_class (self ):
19+ def setup_class (cls ):
1920 """Setup default values"""
20- self .test_turbine = {
21+ cls .test_turbine = {
2122 "hub_height" : 100 ,
2223 "turbine_type" : "E-126/4200" ,
2324 "power_curve" : pd .DataFrame (
@@ -31,7 +32,7 @@ def setup_class(self):
3132 wind_speed_8m = np .array ([[4.0 ], [5.0 ]])
3233 wind_speed_10m = np .array ([[5.0 ], [6.5 ]])
3334 roughness_length = np .array ([[0.15 ], [0.15 ]])
34- self .weather_df = pd .DataFrame (
35+ cls .weather_df = pd .DataFrame (
3536 np .hstack (
3637 (
3738 temperature_2m ,
@@ -434,23 +435,54 @@ def test_modelchain_with_power_coefficient_curve_as_dict(self):
434435
435436 def test_heigths_as_string (self ):
436437 """Test run_model if data heights are of type string."""
437- test_turbine = {'hub_height' : 100 ,
438- 'rotor_diameter' : 80 ,
439- 'turbine_type' : 'E-126/4200' }
438+ test_turbine = {
439+ "hub_height" : 100 ,
440+ "rotor_diameter" : 80 ,
441+ "turbine_type" : "E-126/4200" ,
442+ }
440443
441444 # Convert data heights to str
442445 string_weather = self .weather_df .copy ()
443- string_weather .columns = pd .MultiIndex .from_arrays ([
444- string_weather .columns .get_level_values (0 ),
445- string_weather .columns .get_level_values (1 ).astype (str )])
446+ string_weather .columns = pd .MultiIndex .from_arrays (
447+ [
448+ string_weather .columns .get_level_values (0 ),
449+ string_weather .columns .get_level_values (1 ).astype (str ),
450+ ]
451+ )
446452
447453 # Heights in the original DataFrame are of type np.int64
448- assert isinstance (self .weather_df .columns .get_level_values (1 )[0 ],
449- np .int64 )
454+ assert isinstance (
455+ self .weather_df .columns .get_level_values (1 )[0 ], np .int64
456+ )
450457 assert isinstance (string_weather .columns .get_level_values (1 )[0 ], str )
451458
452- test_modelchain = {'power_output_model' : 'power_curve' ,
453- 'density_corr' : True }
454- test_mc = mc .ModelChain (wt .WindTurbine (** test_turbine ),
455- ** test_modelchain )
459+ test_modelchain = {
460+ "power_output_model" : "power_curve" ,
461+ "density_corr" : True ,
462+ }
463+ test_mc = mc .ModelChain (
464+ wt .WindTurbine (** test_turbine ), ** test_modelchain
465+ )
456466 test_mc .run_model (string_weather )
467+
468+ def test_weather_with_nan_values (self , recwarn ):
469+ """Test warning if weather data contain nan values."""
470+ test_turbine = {
471+ "hub_height" : 100 ,
472+ "rotor_diameter" : 80 ,
473+ "turbine_type" : "E-126/4200" ,
474+ }
475+ nan_weather = self .weather_df .copy ()
476+ nan_weather .loc [1 , ("temperature" , 10 )] = np .nan
477+ test_modelchain = {
478+ "power_output_model" : "power_curve" ,
479+ "density_corr" : True ,
480+ }
481+ test_mc = mc .ModelChain (
482+ wt .WindTurbine (** test_turbine ), ** test_modelchain
483+ )
484+ msg = "'temperature', 10"
485+ with pytest .warns (WindpowerlibUserWarning , match = msg ):
486+ test_mc .run_model (nan_weather )
487+ test_mc .run_model (self .weather_df )
488+ assert len (recwarn ) == 0
0 commit comments