Skip to content

Commit 66bbe0c

Browse files
committed
Convert str to numeric in TurbineClusterModelChain incl. test
1 parent c4a5dbd commit 66bbe0c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/test_turbine_cluster_modelchain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,21 @@ def test_tc_modelchain_with_power_curve_as_dict(self):
272272
power_plant=wtc.WindTurbineCluster(**my_cluster))
273273
test_tc_mc.run_model(self.weather_df)
274274
assert_series_equal(test_tc_mc.power_output, power_output_exp)
275+
276+
def test_heigths_as_string(self):
277+
"""Test run_model if data heights are of type string."""
278+
279+
# Convert data heights to str
280+
string_weather = self.weather_df.copy()
281+
string_weather.columns = pd.MultiIndex.from_arrays([
282+
string_weather.columns.get_level_values(0),
283+
string_weather.columns.get_level_values(1).astype(str)])
284+
285+
# Heights in the original DataFrame are of type np.int64
286+
assert isinstance(self.weather_df.columns.get_level_values(1)[0],
287+
np.int64)
288+
assert isinstance(string_weather.columns.get_level_values(1)[0], str)
289+
290+
test_mc = tc_mc.TurbineClusterModelChain(
291+
power_plant=wtc.WindTurbineCluster(**self.test_cluster))
292+
test_mc.run_model(string_weather)

windpowerlib/turbine_cluster_modelchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
SPDX-License-Identifier: MIT
99
"""
1010
import logging
11+
import pandas as pd
1112
from windpowerlib import wake_losses
1213
from windpowerlib.modelchain import ModelChain
1314

@@ -266,6 +267,10 @@ def run_model(self, weather_df):
266267
'wind_speed'
267268
268269
"""
270+
# Convert data heights to integer. In some case they are strings.
271+
weather_df.columns = pd.MultiIndex.from_arrays([
272+
weather_df.columns.get_level_values(0),
273+
pd.to_numeric(weather_df.columns.get_level_values(1))])
269274

270275
self.assign_power_curve(weather_df)
271276
self.power_plant.mean_hub_height()

0 commit comments

Comments
 (0)