Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Apr 12, 2024
1 parent 07b1df3 commit 0135454
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ requirements:
- premise
- pyyaml
- bw_processing
- bw2calc == 2.0.DEV16
- bw2calc = 2.0.DEV16
- datapackage
- pyprind
- platformdirs
Expand Down
28 changes: 11 additions & 17 deletions pathways/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"""

import logging
import warnings
from collections import defaultdict
from multiprocessing import Pool, cpu_count
from typing import List, Optional
from typing import List, Optional, Any

import numpy as np
import pandas
import pandas as pd
import pyprind
import xarray as xr
Expand All @@ -34,10 +32,6 @@
resize_scenario_data,
)

# remove warnings
# warnings.filterwarnings("ignore")


def _get_mapping(data) -> dict:
"""
Read the mapping file which maps scenario variables to LCA datasets.
Expand All @@ -60,9 +54,9 @@ def _read_scenario_data(data: dict, scenario: str):
# if CSV file
if filepath.endswith(".csv"):
return pd.read_csv(filepath, index_col=0)
else:
# Excel file
return pd.read_excel(filepath, index_col=0)

# Excel file
return pd.read_excel(filepath, index_col=0)


def _read_datapackage(datapackage: str) -> DataPackage:
Expand Down Expand Up @@ -130,7 +124,7 @@ def _get_final_energy_mapping(self):
:return: dict
"""

def create_dict_for_specific_model(row: dict, model: str) -> dict:
def create_dict_for_specific_model(row: pd.Series, model: str) -> dict[Any, Any] | None:
"""
Create a dictionary for a specific model from the row.
:param row: dict
Expand Down Expand Up @@ -159,7 +153,7 @@ def create_dict_for_specific_model(row: dict, model: str) -> dict:
return None

def create_dict_with_specific_model(
dataframe: pandas.DataFrame, model: str
dataframe: pd.DataFrame, model: str
) -> dict:
"""
Create a dictionary for a specific model from the dataframe.
Expand All @@ -168,7 +162,7 @@ def create_dict_with_specific_model(
:return: dict
"""
model_dict = {}
for index, row in dataframe.iterrows():
for _, row in dataframe.iterrows():
row_dict = create_dict_for_specific_model(row, model)
if row_dict:
model_dict.update(row_dict)
Expand Down Expand Up @@ -327,7 +321,7 @@ def calculate(

# Create xarray for storing LCA results if not already present
if self.lca_results is None:
_, technosphere_index, biosphere_index = get_lca_matrices(
_, technosphere_index, _ = get_lca_matrices(
self.filepaths, models[0], scenarios[0], years[0]
)
locations = fetch_inventories_locations(technosphere_index)
Expand All @@ -341,7 +335,7 @@ def calculate(
scenarios=scenarios,
classifications=self.classifications,
mapping=self.mapping,
use_distributions=True if use_distributions > 0 else False,
use_distributions=use_distributions > 0,
)

# Iterate over each combination of model, scenario, and year
Expand Down Expand Up @@ -430,9 +424,9 @@ def _fill_in_result_array(self, results: dict):
}

# use pyprint to display progress
bar = pyprind.ProgBar(len(results))
progress_bar = pyprind.ProgBar(len(results))
for coord, result in results.items():
bar.update()
progress_bar.update()
model, scenario, year = coord
acts_category_idx_dict = result["other"]["acts_category_idx_dict"]
acts_location_idx_dict = result["other"]["acts_location_idx_dict"]
Expand Down

0 comments on commit 0135454

Please sign in to comment.