Skip to content

Commit

Permalink
Apply code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
awais307 committed Sep 29, 2023
1 parent 9c723ab commit cd2aa1b
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 68 deletions.
13 changes: 10 additions & 3 deletions message_ix_models/model/disutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@

from message_ix_models import ScenarioInfo, Spec
from message_ix_models.model.build import apply_spec
from message_ix_models.util import (broadcast, eval_anno, make_io,
make_matched_dfs, make_source_tech,
merge_data, nodes_ex_world, same_node)
from message_ix_models.util import (
broadcast,
eval_anno,
make_io,
make_matched_dfs,
make_source_tech,
merge_data,
nodes_ex_world,
same_node,
)

log = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/model/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from iam_units import registry
from sdmx.model.v21 import Annotation, Code

from message_ix_models.util import (eval_anno, load_package_data,
package_data_path)
from message_ix_models.util import eval_anno, load_package_data, package_data_path
from message_ix_models.util.sdmx import as_codes

log = logging.getLogger(__name__)
Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/model/water/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from message_ix_models import ScenarioInfo
from message_ix_models.util import add_par_data

from .demands import (add_irrigation_demand, add_sectoral_demands,
add_water_availability)
from .demands import add_irrigation_demand, add_sectoral_demands, add_water_availability
from .infrastructure import add_desalination, add_infrastructure_techs
from .irrigation import add_irr_structure
from .water_for_ppl import cool_tech, non_cooling_tec
Expand Down
9 changes: 7 additions & 2 deletions message_ix_models/model/water/data/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
from message_ix import make_df

from message_ix_models.model.water.utils import map_yv_ya_lt
from message_ix_models.util import (broadcast, make_matched_dfs,
private_data_path, same_node, same_time)
from message_ix_models.util import (
broadcast,
make_matched_dfs,
private_data_path,
same_node,
same_time,
)


def add_infrastructure_techs(context): # noqa: C901
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
mapping used in the nexus module.
"""
import glob

# Import packages
import os
from datetime import datetime as dt
Expand Down
11 changes: 7 additions & 4 deletions message_ix_models/model/water/data/water_for_ppl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import pandas as pd
from message_ix import make_df

from message_ix_models.model.water.data.water_supply import \
map_basin_region_wat
from message_ix_models.util import (broadcast, make_matched_dfs,
private_data_path, same_node)
from message_ix_models.model.water.data.water_supply import map_basin_region_wat
from message_ix_models.util import (
broadcast,
make_matched_dfs,
private_data_path,
same_node,
)


# water & electricity for cooling technologies
Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/model/water/data/water_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from message_ix_models.model.water.data.demands import read_water_availability
from message_ix_models.model.water.utils import map_yv_ya_lt
from message_ix_models.util import (broadcast, private_data_path, same_node,
same_time)
from message_ix_models.util import broadcast, private_data_path, same_node, same_time


def map_basin_region_wat(context):
Expand Down
5 changes: 3 additions & 2 deletions message_ix_models/model/water/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from message_ix_models.util import private_data_path

try:
from message_data.tools.post_processing.iamc_report_hackathon import \
report as old_reporting
from message_data.tools.post_processing.iamc_report_hackathon import (
report as old_reporting,
)
except ImportError: # message_data not installed
old_reporting = None

Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/report/computations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Atomic reporting operations for MESSAGEix-GLOBIOM."""
import itertools
import logging
from typing import (TYPE_CHECKING, Any, List, Mapping, Optional, Set, Tuple,
Union)
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Set, Tuple, Union

import ixmp
import pandas as pd
Expand Down
8 changes: 6 additions & 2 deletions message_ix_models/tests/model/test_disutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

from message_ix_models import ScenarioInfo, testing
from message_ix_models.model import disutility
from message_ix_models.util import (add_par_data, copy_column,
make_source_tech, merge_data)
from message_ix_models.util import (
add_par_data,
copy_column,
make_source_tech,
merge_data,
)

# Common data and fixtures for test_minimal() and other tests

Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/tests/model/test_emissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from message_ix.models import MACRO

from message_ix_models import testing
from message_ix_models.model.emissions import (add_tax_emission,
get_emission_factors)
from message_ix_models.model.emissions import add_tax_emission, get_emission_factors


def add_test_data(scenario):
Expand Down
13 changes: 8 additions & 5 deletions message_ix_models/tests/model/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from iam_units import registry
from sdmx.model.v21 import Annotation, Code

from message_ix_models.model.structure import (codelists,
generate_set_elements,
get_codes, get_region_codes,
process_commodity_codes,
process_units_anno)
from message_ix_models.model.structure import (
codelists,
generate_set_elements,
get_codes,
get_region_codes,
process_commodity_codes,
process_units_anno,
)
from message_ix_models.util import as_codes, eval_anno


Expand Down
12 changes: 8 additions & 4 deletions message_ix_models/tests/model/water/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import pandas as pd
import xarray as xr

from message_ix_models.model.water import (Context, add_commodity_and_level,
build, map_add_on, map_yv_ya_lt,
read_config)
from message_ix_models.model.water import (
Context,
add_commodity_and_level,
map_add_on,
map_yv_ya_lt,
read_config,
)


def test_read_config():
Expand All @@ -29,7 +33,7 @@ def test_read_config():

def test_map_add_on():
# Mock the context
context = Context(0)
Context(0)

# Mock the data returned by read_config
mock_data = {
Expand Down
13 changes: 8 additions & 5 deletions message_ix_models/tests/model/water/test_water_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import pandas as pd

from message_ix_models.model.water.data.water_supply import (
add_e_flow, add_water_supply, map_basin_region_wat)
add_e_flow,
add_water_supply,
map_basin_region_wat,
)


def test_map_basin_region_wat():
Expand All @@ -19,7 +22,7 @@ def test_map_basin_region_wat():
}

# Mock the DataFrames read from CSV
df_x = pd.DataFrame(
pd.DataFrame(
{
"BCU_name": ["test_BCU"],
}
Expand Down Expand Up @@ -65,14 +68,14 @@ def test_add_water_supply():
# Mock the DataFrames read from CSV
df_node = pd.DataFrame({"BCU_name": ["test_BCU"], "REGION": ["test_REGION"]})

df_gwt = pd.DataFrame(
pd.DataFrame(
{
"REGION": ["test_REGION"],
"GW_per_km3_per_year": [1],
}
)

df_hist = pd.DataFrame(
pd.DataFrame(
{
"BCU_name": ["test_BCU"],
"hist_cap_sw_km3_year": [1],
Expand Down Expand Up @@ -126,7 +129,7 @@ def test_add_e_flow():
{"Region": ["test_Region"], "value": [1], "year": [2020], "time": ["year"]}
)

df_env = pd.DataFrame(
pd.DataFrame(
{"Region": ["test_Region"], "value": [1], "year": [2020], "time": ["year"]}
)

Expand Down
10 changes: 8 additions & 2 deletions message_ix_models/tests/project/test_ssp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import pytest

from message_ix_models.project.ssp import (SSP, SSP_2017, SSP_2024, generate,
parse, ssp_field)
from message_ix_models.project.ssp import (
SSP,
SSP_2017,
SSP_2024,
generate,
parse,
ssp_field,
)


def test_generate(tmp_path, test_context):
Expand Down
32 changes: 23 additions & 9 deletions message_ix_models/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@
from pandas.testing import assert_series_equal

from message_ix_models import ScenarioInfo
from message_ix_models.util import (MESSAGE_DATA_PATH, MESSAGE_MODELS_PATH,
as_codes, broadcast, check_support,
convert_units, copy_column, ffill,
iter_parameters, load_package_data,
load_private_data, local_data_path,
make_source_tech, maybe_query,
package_data_path, private_data_path,
replace_par_data, same_node, same_time,
series_of_pint_quantity, strip_par_data)
from message_ix_models.util import (
MESSAGE_DATA_PATH,
MESSAGE_MODELS_PATH,
as_codes,
broadcast,
check_support,
convert_units,
copy_column,
ffill,
iter_parameters,
load_package_data,
load_private_data,
local_data_path,
make_source_tech,
maybe_query,
package_data_path,
private_data_path,
replace_par_data,
same_node,
same_time,
series_of_pint_quantity,
strip_par_data,
)

_actual_package_data = Path(__file__).parents[1].joinpath("data")

Expand Down
9 changes: 7 additions & 2 deletions message_ix_models/tests/tools/test_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import pytest

from message_ix_models.tools.advance import (DIMS, LOCATION, _fuzz_data,
advance_data, get_advance_data)
from message_ix_models.tools.advance import (
DIMS,
LOCATION,
_fuzz_data,
advance_data,
get_advance_data,
)
from message_ix_models.util import package_data_path


Expand Down
9 changes: 6 additions & 3 deletions message_ix_models/tests/tools/test_exo_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import pytest
from genno import Computer

from message_ix_models.tools.exo_data import (DemoSource, ExoDataSource,
prepare_computer,
register_source)
from message_ix_models.tools.exo_data import (
DemoSource,
ExoDataSource,
prepare_computer,
register_source,
)


class TestExoDataSource:
Expand Down
8 changes: 6 additions & 2 deletions message_ix_models/tests/util/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

from message_ix_models.model.bare import create_res
from message_ix_models.model.structure import get_codes
from message_ix_models.util import (adapt_R11_R12, adapt_R11_R14, broadcast,
identify_nodes)
from message_ix_models.util import (
adapt_R11_R12,
adapt_R11_R14,
broadcast,
identify_nodes,
)
from message_ix_models.util.node import MappingAdapter


Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/tests/util/test_scenarioinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from sdmx.model.v21 import Code

from message_ix_models import ScenarioInfo, Spec
from message_ix_models.model.structure import (get_codes,
process_technology_codes)
from message_ix_models.model.structure import get_codes, process_technology_codes
from message_ix_models.util import as_codes


Expand Down
8 changes: 6 additions & 2 deletions message_ix_models/tools/advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import pint
from genno import Quantity

from message_ix_models.util import (cached, local_data_path, maybe_query,
private_data_path)
from message_ix_models.util import (
cached,
local_data_path,
maybe_query,
private_data_path,
)

log = logging.getLogger(__name__)

Expand Down
17 changes: 12 additions & 5 deletions message_ix_models/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from collections import ChainMap, defaultdict
from typing import (Collection, Dict, Mapping, MutableMapping, Optional,
Sequence, Union)
from typing import Collection, Dict, Mapping, MutableMapping, Optional, Sequence, Union

import message_ix
import pandas as pd
Expand All @@ -10,9 +9,17 @@

from ._convert_units import convert_units, series_of_pint_quantity
from .cache import cached
from .common import (MESSAGE_DATA_PATH, MESSAGE_MODELS_PATH, Adapter,
MappingAdapter, load_package_data, load_private_data,
local_data_path, package_data_path, private_data_path)
from .common import (
MESSAGE_DATA_PATH,
MESSAGE_MODELS_PATH,
Adapter,
MappingAdapter,
load_package_data,
load_private_data,
local_data_path,
package_data_path,
private_data_path,
)
from .node import adapt_R11_R12, adapt_R11_R14, identify_nodes, nodes_ex_world
from .scenarioinfo import ScenarioInfo, Spec
from .sdmx import CodeLike, as_codes, eval_anno
Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import os
from dataclasses import dataclass, field, fields, is_dataclass, replace
from pathlib import Path
from typing import (Any, Hashable, Mapping, MutableMapping, Optional, Sequence,
Set)
from typing import Any, Hashable, Mapping, MutableMapping, Optional, Sequence, Set

import ixmp

Expand Down
Loading

0 comments on commit cd2aa1b

Please sign in to comment.