Closed jbussemaker closed 9 months ago
I am also getting this future warning, e.g. from example 1
pdopt-code/example/example_1/HE_Model.py:324: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[0.21654579 0.22007194 0.2235981 0.22712425 0.2306504 0.23417656
0.23770271 0.24122887 0.24475502 0.24828118 0.25180733 0.25533348
0.25885964 0.26238579 0.26591195 0.2694381 0.27296426 0.27649041
0.28001656 0.28354272 0.28706887 0.29059503 0.29412118 0.29764734
0.30117349 0.30469965 0.3082258 0.31175195 0.31527811 0.31880426]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
and example 2
pdopt-code/example/example_2/HE_Model.py:324: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[0.0958239 0.09273458 0.08964526 0.08655594 0.08346662 0.08037729
0.07728797 0.07419865 0.07110933 0.06802001 0.06493069 0.06184137
0.05875204 0.05566272 0.0525734 0.04948408 0.04639476 0.04330544
0.04021611 0.03712679 0.03403747 0.03094815 0.02785883 0.02476951
0.02168019 0.01859086 0.01550154 0.01241222 0.0093229 0.00623358]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
mission.loc[mission['tag'] == s, 'pDOH'] = tmp
Running
Dear @jbussemaker @e-dub
I ran the code on a fresh installation and had the same FutureWarning issue.
It stems from when the file mission.csv
is loaded in the code at line 336 of HE_model.py: https://github.com/spinjet/pdopt-code/blob/d2bf7d21ed99f6790ab0c4ec7ca927a0e4a6cc6b/example/example_1/HE_Model.py#L335
In the .csv file the column pDOH only contains zeros, hence Pandas interpreted it as a int64 type. As the degree of hybridisation is then defined in the function generate_doh
, this is replaced with a float value from 0 to 1. It seems in previous versions of Pandas this recast didn't throw any Warnings, hence I never noticed it.
This has now been fiixed by ensuring the dtype of the pDOH column in the dataframe is set to float when the energy management strategy is created (see in https://github.com/spinjet/pdopt-code/blob/31f65670a6fa449833f975c7cba305950c74c2ad/example/example_1/HE_Model.py#L330):
mission.loc[mission['tag'] == s, 'pDOH'] = None
mission.loc[mission['tag'] == s, 'pDOH'] = tmp.astype(float)
I also took the opportunity to do a bit of linting in the example files.
Environment: Python 12 env created with conda, dependencies installed with
pip install -r requirements.txt
When I run
energy_management_experiment.py
inexample_1
, I continuously get the following warnings:The env has pandas 2.1.4 installed.
Part of JOSS submission