Skip to content
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
23 changes: 23 additions & 0 deletions tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions windpowerlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SPDX-License-Identifier: MIT
"""
import logging
import pandas as pd
from windpowerlib import (wind_speed, density, temperature, power_output,
tools)

Expand Down Expand Up @@ -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)
Expand Down