Skip to content

Commit

Permalink
chore: make sure we support python 3.8 to 3.11 (#475)
Browse files Browse the repository at this point in the history
* fix: compare operators with tokens instead of counting operators in tokens in expression (#485)
* chore: set dependency resolutions according to support in python 3.x

Refs: ECALC-994, ECALC-1141
  • Loading branch information
TeeeJay authored May 15, 2024
1 parent ab2877e commit 2e26ce1
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lib-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9" ]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
235 changes: 226 additions & 9 deletions poetry.lock

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,33 @@ ecalc = 'ecalc_cli.main:main'
[tool.poetry.dependencies]
python = ">=3.8,<3.12"
pydantic = "<3"
PyYAML = "^6.0"
numpy = "~1.24.0"
PyYAML = "^6"
numpy = [
{version = "~1.24.0", python="<3.9"},
{version = "~1.26.0", python=">=3.9"},
]
pandas = [
{version = ">= 1.5, < 2.1", python="<3.9"},
{version = "~2", python=">=3.9"},
]
scipy = "^1.10"
"ruamel.yaml" = "^0.17.21"
Shapely = "^2.0"
networkx = "^3.1"
orjson = "^3.8.11"
scipy = [
{version = "~1.10", python="<3.9"},
{version = ">= 1.12, < 1.14", python=">=3.9"},
]
"ruamel.yaml" = "^0.18"
Shapely = "^2"
networkx = [
{version = "~3.1", python="<3.9"},
{version = "^3.2", python=">=3.9"},
]
orjson = "^3.8"
py4j = "^0.10"
rich = "^13.7.1" # also used for typer as optional dependency
jupyter = {version = "^1.0.0", optional = true}
matplotlib = {version = "^3.7.1", optional = true}
matplotlib = [
{version = "~3.7", python="<3.9", optional = true},
{version = "^3.8", python=">=3.9", optional = true},
]
typer = "^0.12.3"

[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/dto/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
def check_model_energy_usage_type(model_data: Dict[datetime, ConsumerFunction], energy_type: EnergyUsageType):
for model in model_data.values():
if model.energy_usage_type != energy_type:
raise ValueError(f"Model does not consume {energy_type}")
raise ValueError(f"Model does not consume {energy_type.value}")
return model_data


Expand Down
12 changes: 3 additions & 9 deletions src/libecalc/expression/expression_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ def eval_additions(tokens):
values = []
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if tokens.count("{+}") or tokens.count(
"{-}"
): # Fixme: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if any(ops in token if hasattr(token, "__iter__") else ops == token for token in tokens for ops in add_ops):
ind = 0
seqstart = 0
signNext = 1.0
Expand Down Expand Up @@ -178,9 +176,7 @@ def eval_mults(tokens):
np.seterr(divide="ignore", invalid="ignore")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if tokens.count("{*}") or tokens.count(
"{/}"
): # Fixme: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if any(ops in token if hasattr(token, "__iter__") else ops == token for token in tokens for ops in mult_ops):
ind = 0
seqstart = 0
opnext = "mult"
Expand Down Expand Up @@ -219,9 +215,7 @@ def eval_powers(tokens):
"""Evaluate exponential calculations in expression"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
if tokens.count(
"{^}"
): # Fixme: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if any("{^}" in token if hasattr(token, "__iter__") else "{^}" == token for token in tokens):
if len(tokens) != 3:
raise ValueError("Number of tokens needs to be 3 for evalPowers, quotient, {^} and exponent")
quotient = eval_value([tokens[0]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_direct_consumers_yaml(
ENERGY_USAGE_MODEL:
TYPE: DIRECT
FUELRATE: {fuel_rate}
CONSUMPTION_RATE_TYPE: {rate_type}
CONSUMPTION_RATE_TYPE: {rate_type.value}
"""
consumers = consumers + consumer
return consumers
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def create_venting_emitters_yaml(
RATE:
VALUE: {emission_rate}
UNIT: {unit}
TYPE: {rate_type}
TYPE: {rate_type.value}
"""
emissions = emissions + emission
else:
Expand All @@ -158,7 +158,7 @@ def create_venting_emitters_yaml(
RATE:
VALUE: {oil_rate}
UNIT: {unit_oil_rate}
TYPE: {rate_type}
TYPE: {rate_type.value}
EMISSIONS:
"""
for emission_name, emission_factor in zip(emission_names, emission_factors):
Expand Down

0 comments on commit 2e26ce1

Please sign in to comment.