pybamm-team / liionpack

A battery pack simulation tool that uses the PyBaMM framework
https://liionpack.readthedocs.io/en/latest/
MIT License
83 stars 26 forks source link

FutureWarning about Incompatible Dtype in netlist_utils.py When Setting Item #285

Closed lappemic closed 4 months ago

lappemic commented 5 months ago

I encountered a FutureWarning while working with liionpack that seems related to a potential future error due to setting an item with an incompatible dtype in netlist_utils.py. The warning suggests that a future version of pandas will raise an error for this operation, specifically when setting values of a dtype incompatible with int64.

Here's the warning message I received:

/home/mlappert/batterypipeline/venv_batterypipeline/lib/python3.11/site-packages/liionpack/
netlist_utils.py:736: FutureWarning: Setting an item of incompatible dtype is deprecated and 
will raise an error in a future version of pandas. Value '[2.11290499e-05 2.53498513e-05 
9.42634428e-06 1.40860332e-04 1.28029748e-06 2.57317642e-05 6.28422952e-05 2.11290499e-05
 2.53498513e-05 9.42634428e-06 1.97215226e-26 1.86621483e-25]' has dtype incompatible 
with int64, please explicitly cast to a compatible dtype first. netlist.loc[R_map, ("power_loss")] = P_loss

I am currently using pybamm version 23.4 and pandas==2.2.0. It looks like the code is attempting to assign a non-integer array to a pandas DataFrame column that expects integer values, which might not be an issue now but could cause errors with future pandas releases.

TomTranter commented 4 months ago

This should be fixed already in the released version. I guess you may have cloned the source and were using the main branch as this was out of date. I have just updated it and made a new release from develop