Skip to content

Commit

Permalink
fix: PR CI ruff autofixes
Browse files Browse the repository at this point in the history
  • Loading branch information
irm-codebase committed Sep 30, 2024
1 parent d024911 commit 527dfa9
Show file tree
Hide file tree
Showing 31 changed files with 133 additions and 164 deletions.
3 changes: 1 addition & 2 deletions docs/examples/loading_tabular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
# %%
from pathlib import Path

import pandas as pd

import calliope
import pandas as pd

calliope.set_log_verbosity("INFO", include_solver_output=False)

Expand Down
3 changes: 1 addition & 2 deletions docs/examples/national_scale/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
# This notebook will show you how to load, build, solve, and examine the results of the national scale example model.

# %%
import calliope
import pandas as pd
import plotly.express as px

import calliope

# We increase logging verbosity
calliope.set_log_verbosity("INFO", include_solver_output=False)

Expand Down
3 changes: 1 addition & 2 deletions docs/examples/piecewise_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

# %%

import calliope
import numpy as np
import plotly.express as px

import calliope

calliope.set_log_verbosity("INFO", include_solver_output=False)

# %% [markdown]
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/urban_scale/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
# This notebook will show you how to load, build, solve, and examine the results of the urban scale example model.

# %%
import calliope
import pandas as pd
import plotly.express as px

import calliope

# We increase logging verbosity
calliope.set_log_verbosity("INFO", include_solver_output=False)

Expand Down
3 changes: 1 addition & 2 deletions docs/hooks/generate_math_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import textwrap
from pathlib import Path

from mkdocs.structure.files import File

import calliope
from calliope.postprocess.math_documentation import MathDocumentation
from mkdocs.structure.files import File

logger = logging.getLogger("mkdocs")

Expand Down
3 changes: 1 addition & 2 deletions docs/hooks/generate_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import tempfile
from pathlib import Path

import calliope
import pandas as pd
import plotly.graph_objects as go
import xarray as xr
from mkdocs.structure.files import File

import calliope

TEMPDIR = tempfile.TemporaryDirectory()


Expand Down
3 changes: 1 addition & 2 deletions docs/hooks/generate_readable_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from pathlib import Path

import jsonschema2md
from mkdocs.structure.files import File

from calliope.util import schema
from mkdocs.structure.files import File

TEMPDIR = tempfile.TemporaryDirectory()

Expand Down
3 changes: 1 addition & 2 deletions tests/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from pathlib import Path
from typing import Literal

import xarray as xr

import calliope
import calliope.backend
import calliope.preprocess
import xarray as xr


def build_test_model(
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pytest
import xarray as xr

from calliope.attrdict import AttrDict
from calliope.backend import latex_backend_model, pyomo_backend_model
from calliope.preprocess import CalliopeMath
Expand Down Expand Up @@ -54,7 +53,7 @@ def simple_supply():
return m


@pytest.fixture
@pytest.fixture()
def simple_supply_build_func():
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build()
Expand Down
47 changes: 23 additions & 24 deletions tests/test_backend_expression_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pyparsing as pp
import pytest
import xarray as xr

from calliope import exceptions
from calliope.backend import expression_parser, helper_functions

Expand Down Expand Up @@ -37,53 +36,53 @@ def as_array(self, x, y):
return x * 10 + y


@pytest.fixture
@pytest.fixture()
def valid_component_names():
return ["foo", "with_inf", "only_techs", "no_dims", "multi_dim_var", "no_dim_var"]


@pytest.fixture
@pytest.fixture()
def base_parser_elements():
number, identifier = expression_parser.setup_base_parser_elements()
return number, identifier


@pytest.fixture
@pytest.fixture()
def number(base_parser_elements):
return base_parser_elements[0]


@pytest.fixture
@pytest.fixture()
def identifier(base_parser_elements):
return base_parser_elements[1]


@pytest.fixture
@pytest.fixture()
def evaluatable_identifier(identifier, valid_component_names):
return expression_parser.evaluatable_identifier_parser(
identifier, valid_component_names
)


@pytest.fixture
@pytest.fixture()
def id_list(number, evaluatable_identifier):
return expression_parser.list_parser(number, evaluatable_identifier)


@pytest.fixture
@pytest.fixture()
def unsliced_param():
def _unsliced_param(valid_component_names):
return expression_parser.unsliced_object_parser(valid_component_names)

return _unsliced_param


@pytest.fixture
@pytest.fixture()
def unsliced_param_with_obj_names(unsliced_param, valid_component_names):
return unsliced_param(valid_component_names)


@pytest.fixture
@pytest.fixture()
def sliced_param(
number, identifier, evaluatable_identifier, unsliced_param_with_obj_names
):
Expand All @@ -92,12 +91,12 @@ def sliced_param(
)


@pytest.fixture
@pytest.fixture()
def sub_expression(identifier):
return expression_parser.sub_expression_parser(identifier)


@pytest.fixture
@pytest.fixture()
def helper_function(
number,
sliced_param,
Expand All @@ -117,7 +116,7 @@ def helper_function(
)


@pytest.fixture
@pytest.fixture()
def helper_function_no_nesting(
number,
sliced_param,
Expand Down Expand Up @@ -158,7 +157,7 @@ def helper_function_one_parser_in_args(identifier, request):
)


@pytest.fixture
@pytest.fixture()
def eval_kwargs(dummy_pyomo_backend_model):
return {
"helper_functions": helper_functions._registry["expression"],
Expand All @@ -173,7 +172,7 @@ def eval_kwargs(dummy_pyomo_backend_model):
}


@pytest.fixture
@pytest.fixture()
def arithmetic(
helper_function, number, sliced_param, sub_expression, unsliced_param_with_obj_names
):
Expand All @@ -186,7 +185,7 @@ def arithmetic(
)


@pytest.fixture
@pytest.fixture()
def helper_function_allow_arithmetic(
number,
sliced_param,
Expand All @@ -210,22 +209,22 @@ def helper_function_allow_arithmetic(
)


@pytest.fixture
@pytest.fixture()
def equation_comparison(arithmetic):
return expression_parser.equation_comparison_parser(arithmetic)


@pytest.fixture
@pytest.fixture()
def generate_equation(valid_component_names):
return expression_parser.generate_equation_parser(valid_component_names)


@pytest.fixture
@pytest.fixture()
def generate_slice(valid_component_names):
return expression_parser.generate_slice_parser(valid_component_names)


@pytest.fixture
@pytest.fixture()
def generate_sub_expression(valid_component_names):
return expression_parser.generate_sub_expression_parser(valid_component_names)

Expand Down Expand Up @@ -759,19 +758,19 @@ def var_left(self, request):
def var_right(self, request):
return request.param

@pytest.fixture
@pytest.fixture()
def expected_left(self, var_left):
return self.EXPR_PARAMS_AND_EXPECTED_EVAL[var_left]

@pytest.fixture
@pytest.fixture()
def expected_right(self, var_right):
return self.EXPR_PARAMS_AND_EXPECTED_EVAL[var_right]

@pytest.fixture(params=["<=", ">=", "=="])
def operator(self, request):
return request.param

@pytest.fixture
@pytest.fixture()
def single_equation_simple(self, var_left, var_right, operator):
return f"{var_left} {operator} {var_right}"

Expand Down Expand Up @@ -850,7 +849,7 @@ def test_repr(self, equation_comparison):


class TestAsMathString:
@pytest.fixture
@pytest.fixture()
def latex_eval_kwargs(self, dummy_latex_backend_model):
return {
"helper_functions": helper_functions._registry["expression"],
Expand Down
9 changes: 4 additions & 5 deletions tests/test_backend_general.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import logging

import calliope
import numpy as np
import pandas as pd
import pytest # noqa: F401
import xarray as xr

import calliope

from .common.util import build_test_model as build_model
from .common.util import check_error_or_warning

Expand All @@ -26,15 +25,15 @@ def built_model_cls_longnames(backend) -> calliope.Model:
return m


@pytest.fixture
@pytest.fixture()
def built_model_func_longnames(backend) -> calliope.Model:
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build(backend=backend, pre_validate_math_strings=False)
m.backend.verbose_strings()
return m


@pytest.fixture
@pytest.fixture()
def solved_model_func(backend) -> calliope.Model:
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build(backend=backend, pre_validate_math_strings=False)
Expand Down Expand Up @@ -66,7 +65,7 @@ def solved_model_cls(backend) -> calliope.Model:
return m


@pytest.fixture
@pytest.fixture()
def built_model_func_updated_cost_flow_cap(backend, dummy_int: int) -> calliope.Model:
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build(backend=backend, pre_validate_math_strings=False)
Expand Down
9 changes: 4 additions & 5 deletions tests/test_backend_gurobi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import calliope.exceptions as exceptions
import gurobipy
import pytest # noqa: F401
import xarray as xr

import calliope.exceptions as exceptions

from .common.util import build_test_model as build_model
from .common.util import check_error_or_warning

Expand All @@ -25,7 +24,7 @@ def simple_supply_gurobi(self):
m.solve()
return m

@pytest.fixture
@pytest.fixture()
def simple_supply_gurobi_func(self):
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build(backend="gurobi", pre_validate_math_strings=False)
Expand Down Expand Up @@ -261,13 +260,13 @@ def test_to_lp_wrong_file_extension(self, simple_supply_gurobi, tmp_path):


class TestShadowPrices:
@pytest.fixture
@pytest.fixture()
def simple_supply(self):
m = build_model({}, "simple_supply,two_hours,investment_costs")
m.build(backend="gurobi")
return m

@pytest.fixture
@pytest.fixture()
def supply_milp(self):
m = build_model({}, "supply_milp,two_hours,investment_costs")
m.build(backend="gurobi")
Expand Down
Loading

0 comments on commit 527dfa9

Please sign in to comment.