Skip to content

Commit

Permalink
Code satisfies E rules (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne authored Sep 28, 2024
1 parent 72e80b4 commit fab9872
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,5 @@ fabric.properties
docs/reference/

.idea/

tests/tests/.temp/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ check: ## Run code quality tools.
.PHONY: test
test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@poetry run pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
@poetry run pytest -n auto tests --cov --cov-config=pyproject.toml --cov-report=xml

.PHONY: build
build: clean-build ## Build wheel file using poetry
Expand Down
8 changes: 4 additions & 4 deletions archetypal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ def initialize_units(cls, v):
settings.unit_registry = unit_registry

# After settings are loaded, import other modules
from .eplus_interface.version import EnergyPlusVersion
from .idfclass import IDF
from .umi_template import (
from .eplus_interface.version import EnergyPlusVersion # noqa: E402
from .idfclass import IDF # noqa: E402
from .umi_template import ( # noqa: E402
BuildingTemplate,
UmiTemplateLibrary,
)
from .utils import clear_cache, config, parallel_process
from .utils import clear_cache, config, parallel_process # noqa: E402

try:
__version__ = get_distribution("archetypal").version
Expand Down
9 changes: 4 additions & 5 deletions archetypal/idfclass/idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
from math import isclose
from typing import IO, ClassVar, Literal

import numpy as np
from sigfig import round

ReportingFrequency = Literal["Annual", "Monthly", "Daily", "Hourly", "Timestep"]

import eppy
import numpy as np
import pandas as pd
from energy_pandas import EnergySeries
from eppy.bunch_subclass import BadEPFieldError
Expand All @@ -41,6 +37,7 @@
from pandas import DataFrame, Series
from pandas.errors import ParserError
from path import Path
from sigfig import round
from tabulate import tabulate
from tqdm.auto import tqdm

Expand All @@ -67,6 +64,8 @@
from geomeppy.patches import EpBunch, idfreader1, obj2bunch
from geomeppy.recipes import _is_window, window_vertices_given_wall

ReportingFrequency = Literal["Annual", "Monthly", "Daily", "Hourly", "Timestep"]


def find_and_launch(app_name, app_path_guess, file_path):
app_path = shutil.which(app_name, path=app_path_guess)
Expand Down
2 changes: 1 addition & 1 deletion archetypal/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def save_and_show(fig, ax, save, show, close, filename, file_format, dpi, axis_o
os.makedirs(settings.imgs_folder)
path_filename = os.path.join(settings.imgs_folder, os.extsep.join([filename, file_format]))

if not isinstance(ax, (np.ndarray, list)):
if not isinstance(ax, np.ndarray | list):
ax = [ax]
if file_format == "svg":
fig.patch.set_alpha(0.0)
Expand Down
2 changes: 1 addition & 1 deletion archetypal/template/constructions/base_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,4 @@ def __eq__(self, other):

@property
def children(self):
return tuple(l.Material for l in self.Layers)
return tuple(layer.Material for layer in self.Layers)
14 changes: 7 additions & 7 deletions archetypal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def angle(v1, v2, acute=True):
angle (float): angle between the 2 vectors in degree
"""
angle = np.arccos(np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)))
if acute == True:
if acute is True:
return angle
else:
return 2 * np.pi - angle
Expand Down Expand Up @@ -443,9 +443,9 @@ def timed(*args, **kwargs):
try:
try:
name = result.Name
except:
except Exception:
name = result.__qualname__
except:
except Exception:
name = str(result)
if tt > 0.001:
log(f"Completed {method.__qualname__!r} for {name!r} in {tt:.3f} s")
Expand Down Expand Up @@ -512,23 +512,23 @@ def recursive_len(item):
Returns:
Total number of elements in nested list
"""
if type(item) == list:
if isinstance(item, list):
return sum(recursive_len(subitem) for subitem in item)
else:
return 1


def rotate(l, n):
def rotate(items, n):
"""Shift list elements to the left
Args:
l (list): list to rotate
items (list): list to rotate
n (int): number to shift list to the left
Returns:
list: shifted list.
"""
return l[n:] + l[:n]
return items[n:] + items[:n]


def parallel_process(
Expand Down
2 changes: 1 addition & 1 deletion archetypal/zone_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def from_idf(cls, idf, log_adj_report=True, **kwargs):
this_cstr = surface["Construction_Name"]
their_cstr = adj_surf["Construction_Name"]
is_diff_cstr = surface["Construction_Name"] != adj_surf["Construction_Name"]
except:
except Exception:
this_cstr, their_cstr, is_diff_cstr = None, None, None
# create edge from this zone to the adjacent zone
G.add_edge(
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ select = [
# mccabe
"C90",
# pycodestyle
#"E",
"E",
"W",
# pyflakes
"F",
"F",
# pygrep-hooks
"PGH",
# pyupgrade
"UP",
# ruff
"RUF",
# tryceratops
"TRY",
"TRY",
]
ignore = [
# LineTooLong
Expand Down
9 changes: 0 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
import os
import sys
from pathlib import Path
Expand Down Expand Up @@ -30,14 +29,6 @@ def scratch_then_cache(request):
d.rmtree_p()


samples_ = ["regular", "umi_samples"] # ['problematic', 'regular', 'umi_samples']


@pytest.fixture(params=samples_, ids=samples_, scope="session")
def idf_source(request):
return glob.glob(f"tests/input_data/{request.param}/*.idf")


@pytest.fixture(scope="session")
def config():
utils.config(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_energypandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_discretize(self, rd_es):
rd_es.discretize_tsam(noTypicalPeriods=1, inplace=True)
assert_almost_equal(res.sum(), 2.118713381170598, decimal=3)
# check that the type is maintained
assert type(rd_es) == EnergySeries
assert isinstance(res, EnergySeries)


class TestEnergyDataFrame:
Expand All @@ -88,7 +88,7 @@ def test_discretize(self, rd_edf):
rd_edf.discretize_tsam(noTypicalPeriods=1, inplace=True)
assert hasattr(rd_edf, "agg")
# check that the type is maintained
assert type(rd_edf) == EnergyDataFrame
assert isinstance(rd_edf, EnergyDataFrame)

def test_plot_2d(self, rd_edf):
fig, ax = rd_edf.plot2d(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_replace(self):


def schedules_idf():
config(cache_folder=os.getenv("ARCHETYPAL_CACHE") or data_dir / ".temp/cache")
config(cache_folder=os.getenv("ARCHETYPAL_CACHE") or data_dir / "../.temp/cache")
idf = IDF(
idf_file,
epw=data_dir / "CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw",
Expand Down
12 changes: 6 additions & 6 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2089,20 +2089,20 @@ def test_naturalVentilation_from_zone(self, ventilatontests):
zone_ep = idf.getobject("ZONE", "ZONE 1")
z = ZoneDefinition.from_epbunch(ep_bunch=zone_ep, construct_parents=False)
ventilation_setting = VentilationSetting.from_zone(z, zone_ep)
assert ventilation_setting.IsNatVentOn == True
assert ventilation_setting.IsScheduledVentilationOn == False
assert ventilation_setting.IsNatVentOn is True
assert ventilation_setting.IsScheduledVentilationOn is False
if idf_name == "VentilationSimpleTest.idf":
zone_ep = idf.getobject("ZONE", "ZONE 2")
z = ZoneDefinition.from_epbunch(ep_bunch=zone_ep, construct_parents=False)
ventilation_setting = VentilationSetting.from_zone(z, zone_ep)
assert ventilation_setting.IsNatVentOn == False
assert ventilation_setting.IsScheduledVentilationOn == True
assert ventilation_setting.IsNatVentOn is False
assert ventilation_setting.IsScheduledVentilationOn is True
if idf_name == "RefBldgWarehouseNew2004_Chicago.idf":
zone_ep = idf.getobject("ZONE", "Office")
z = ZoneDefinition.from_epbunch(ep_bunch=zone_ep, construct_parents=False)
ventilation_setting = VentilationSetting.from_zone(z, zone_ep)
assert ventilation_setting.IsNatVentOn == False
assert ventilation_setting.IsScheduledVentilationOn == False
assert ventilation_setting.IsNatVentOn is False
assert ventilation_setting.IsScheduledVentilationOn is False

def test_ventilationSetting_from_to_dict(self):
"""Make dict with `to_dict` and load again with `from_dict`."""
Expand Down

0 comments on commit fab9872

Please sign in to comment.