wind-python / windpowerlib

The windpowerlib is a library to model the output of wind turbines and farms.
https://oemof.org/
MIT License
330 stars 105 forks source link

Library does not work at all with python 3.11 #127

Closed mkaut closed 10 months ago

mkaut commented 1 year ago

I wanted to try the library, but nothing seems to work with python 3.11 on Windows. Is the library still maintained?

Already the first code snippet fails:

from windpowerlib.data import store_turbine_data_from_oedb
store_turbine_data_from_oedb()

gives

Traceback (most recent call last):
  File ".py311\Lib\site-packages\windpowerlib\data.py", line 252, in check_turbine_data
    data = check_data_integrity(filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\windpowerlib\data.py", line 269, in check_data_integrity
    wt = WindTurbine(**turbine_data_set)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 142, in __init__
    self.power_curve = get_turbine_data_from_file(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 407, in get_turbine_data_from_file
    wpp_df["wind_speed"] = wpp_df["wind_speed"].apply(lambda x: float(x))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\series.py", line 4771, in apply
    return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\apply.py", line 1123, in apply
    return self.apply_standard()
           ^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\apply.py", line 1174, in apply_standard
    mapped = lib.map_infer(
             ^^^^^^^^^^^^^^
  File "pandas\_libs\lib.pyx", line 2924, in pandas._libs.lib.map_infer
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 407, in <lambda>
    wpp_df["wind_speed"] = wpp_df["wind_speed"].apply(lambda x: float(x))
                                                                ^^^^^^^^
ValueError: could not convert string to float: '7.0.1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".py311\Lib\site-packages\windpowerlib\data.py", line 246, in store_turbine_data_from_oedb
    check_turbine_data(filename)
  File ".py311\Lib\site-packages\windpowerlib\data.py", line 254, in check_turbine_data
    restore_default_turbine_data()
  File ".py311\Lib\site-packages\windpowerlib\data.py", line 309, in restore_default_turbine_data
    for file in os.listdir(src_path):
                ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: '.py311\\Lib\\site-packages\\windpowerlib\\data\\default_turbine_data'

The second code snippet:

from windpowerlib import WindTurbine
enercon_e126 = {
    "turbine_type": "E-126/4200",  # turbine type as in register
    "hub_height": 135,  # in m
}
e126 = WindTurbine(**enercon_e126)

fails as well, and possibly for the same reason:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 142, in __init__
    self.power_curve = get_turbine_data_from_file(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 407, in get_turbine_data_from_file
    wpp_df["wind_speed"] = wpp_df["wind_speed"].apply(lambda x: float(x))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\series.py", line 4771, in apply
    return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\apply.py", line 1123, in apply
    return self.apply_standard()
           ^^^^^^^^^^^^^^^^^^^^^
  File ".py311\Lib\site-packages\pandas\core\apply.py", line 1174, in apply_standard
    mapped = lib.map_infer(
             ^^^^^^^^^^^^^^
  File "pandas\_libs\lib.pyx", line 2924, in pandas._libs.lib.map_infer
  File ".py311\Lib\site-packages\windpowerlib\wind_turbine.py", line 407, in <lambda>
    wpp_df["wind_speed"] = wpp_df["wind_speed"].apply(lambda x: float(x))
                                                                ^^^^^^^^
ValueError: could not convert string to float: '7.0.1'

Windows 10, python 3.11 x64, windpowerlib installed with pip.

uvchik commented 1 year ago

You downloaded the new data from the OEP but the data set is broken. Normally the data set should be restored in that case but it seems to me that the data-restore does not work.

  1. You should inform the OEP maintainer that the database of windpower plants is broken. 2a. You should reinstall the windpowerlib and do NOT update the data using store_turbine_data_from_oedb() 2b. You can download the source code of the dev branch from github and install it using pip install -e c:\path\to\the\downloaded\code

We will try to release a fixed version of the windpowerlib soon. I think the problem is, that the default data is missing. Sorry for that.

...and yes, we do need new maintainer for the windpowerlib.

maurerle commented 1 year ago

FYI: the dev version can also be directly installed as !pip install git+https://github.com/wind-python/windpowerlib@dev

The attached PR fixes both of the two issues.

Though a Pandas Future warning exists:

FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead
  self.nominal_power = float(turbine_data["nominal_power"])

But at least everything is working that way - the FutureWarning does not have to do with it