diff --git a/tests/test_modelchain.py b/tests/test_modelchain.py index fbc1b5d4..2c7f3e76 100644 --- a/tests/test_modelchain.py +++ b/tests/test_modelchain.py @@ -341,3 +341,26 @@ def test_modelchain_with_power_coefficient_curve_as_dict(self): power_output_model='power_coefficient_curve') test_mc.run_model(self.weather_df) assert_series_equal(test_mc.power_output, power_output_exp) + + def test_heigths_as_string(self): + """Test run_model if data heights are of type string.""" + test_turbine = {'hub_height': 100, + 'rotor_diameter': 80, + 'turbine_type': 'E-126/4200'} + + # Convert data heights to str + string_weather = self.weather_df.copy() + string_weather.columns = pd.MultiIndex.from_arrays([ + string_weather.columns.get_level_values(0), + string_weather.columns.get_level_values(1).astype(str)]) + + # Heights in the original DataFrame are of type np.int64 + assert isinstance(self.weather_df.columns.get_level_values(1)[0], + np.int64) + assert isinstance(string_weather.columns.get_level_values(1)[0], str) + + test_modelchain = {'power_output_model': 'power_curve', + 'density_corr': True} + test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine), + **test_modelchain) + test_mc.run_model(string_weather) diff --git a/windpowerlib/modelchain.py b/windpowerlib/modelchain.py index 0a4cfc4e..a1e9d803 100644 --- a/windpowerlib/modelchain.py +++ b/windpowerlib/modelchain.py @@ -7,6 +7,7 @@ SPDX-License-Identifier: MIT """ import logging +import pandas as pd from windpowerlib import (wind_speed, density, temperature, power_output, tools) @@ -438,6 +439,11 @@ def run_model(self, weather_df): 'wind_speed' """ + # Convert data heights to integer. In some case they are strings. + weather_df.columns = pd.MultiIndex.from_arrays([ + weather_df.columns.get_level_values(0), + pd.to_numeric(weather_df.columns.get_level_values(1))]) + wind_speed_hub = self.wind_speed_hub(weather_df) density_hub = (None if (self.power_output_model == 'power_curve' and self.density_correction is False)