Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The idea here is to drastically improve the efficiency of the function fill_xarray_from_input_parameters
Previously, it iterated through all indexes of an initialized xarray DataArray called array.
What I propose here is to keep the same iterative process but instead of allocating values directly to a DataArray, I append dictionnaries into a list. This list of dictionnary is then used to create a pandas DataFrame.
For each column of interest (powertrain, size, value, year, parameter), I flatten (through explode function) the lists contained within each row of the dataframe. I use a dummy variable "g" which count elements in each lists for each row of the DataFrame.
The final DataFrame is built using the flatten dataframe and the corresponding parameters data. NaN are automatically used when a DataFrame is broadcasted. Then I use the ffill method from DataFrame.fillna to replace the NaN by the expected values.
The columns size, powertrain, parameter, year and value are then passed as index of the DataFrame.
The resulting DataArray is created from the final pandas Series obtained.
It was not easy to detailled the process here, do not hesite to ask further question if needed.
All tests in carculator_utils, carculator and carculator_trucks seem to work properly.