Skip to content

Commit 0bba8c6

Browse files
authored
Merge pull request #138 from WISDEM/develop
v0.9.3: Minor Bug Fix and Formatting Updates
2 parents b4eecd8 + 22cd06d commit 0bba8c6

7 files changed

+53
-54
lines changed

.pre-commit-config.yaml

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ repos:
88
name: isort
99
stages: [commit]
1010

11-
- repo: https://github.com/psf/black
12-
rev: 23.12.0
11+
- repo: https://github.com/asottile/pyupgrade
12+
rev: v3.15.0
1313
hooks:
14-
- id: black
15-
name: black
14+
- id: pyupgrade
15+
args: [--py39-plus]
1616
stages: [commit]
1717

18+
- repo: https://github.com/charliermarsh/ruff-pre-commit
19+
rev: v0.1.8
20+
hooks:
21+
- id: ruff
22+
args: [--fix]
23+
- id: ruff-format
24+
types_or: [python, pyi, jupyter]
25+
1826
- repo: https://github.com/pre-commit/mirrors-mypy
1927
rev: 'v1.7.1' # Use the sha / tag you want to point at
2028
hooks:
@@ -38,13 +46,6 @@ repos:
3846
- id: pretty-format-json
3947
args: [--autofix]
4048

41-
42-
- repo: https://github.com/charliermarsh/ruff-pre-commit
43-
rev: v0.1.8
44-
hooks:
45-
- id: ruff
46-
args: [--fix]
47-
4849
# - repo: local
4950
# hooks:
5051
# - id: pytest

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v0.9.3 (15 February 2024)
2+
3+
- Reinstate the original time-based availability methodology, which is based on all
4+
turbines, not the wind farm total.
5+
- Replace the `black` formatter with `ruff`.
6+
- Adopt `pyupgrade` to ensure modern Python language usage.
7+
- Add the NumPy 2.0 integration tool to Ruff.
8+
19
## v0.9.2 (13 November 2023)
210

311
### General

pyproject.toml

+19-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
requires = ["setuptools", "setuptools-scm"]
33
build-backend = "setuptools.build_meta"
44

5+
[metadata]
6+
version = "attr: wombat.__version__"
7+
58
[project]
69
name = "wombat"
710
dynamic = ["version"]
@@ -62,12 +65,12 @@ changelog = "https://github.com/WISDEM/WOMBAT/blob/main/CHANGELOG.md"
6265
[project.optional-dependencies]
6366
dev = [
6467
"pre-commit>=2.20",
65-
"black>=22.1",
6668
"isort>=5.10",
6769
"pytest>=7",
6870
"pytest-cov>=4",
6971
"mypy==0.991",
70-
"ruff==0.0.246",
72+
"ruff>=0.2",
73+
"pyupgrade",
7174
]
7275
docs = [
7376
"jupyter-book>=0.15",
@@ -161,36 +164,27 @@ length_sort = true
161164
lines_after_imports = 2
162165
line_length = 88
163166

164-
165-
[tool.black]
166-
target-version=["py39", "py310"]
167-
line-length=88
168-
169-
include = '\.pyi?$'
170-
exclude = '''
171-
/(
172-
\.git
173-
| \.hg
174-
| \.mypy_cache
175-
| \.tox
176-
| \.venv
177-
| _build
178-
| buck-out
179-
| build
180-
| dist
181-
)/
182-
'''
167+
[tool.numpydoc_validation]
168+
checks = [
169+
"all",
170+
"ES01",
171+
"SA01",
172+
"EX01",
173+
]
174+
exclude = ["*__pycache__"]
183175

184176
[tool.ruff]
185177
src = ["wombat", "tests"]
186178
line-length = 88
187179
target-version = "py39"
188-
ignore-init-module-imports = true
180+
fix = true
189181

182+
[tool.ruff.lint]
190183
# See https://github.com/charliermarsh/ruff#supported-rules
191184
# for rules included and matching to prefix.
192185
# TODO: "FBT", "B", "PIE, "T20", "SIM", "PTH", "PD", "I", "PL"
193-
select = ["F", "E", "W", "C4", "D", "UP"]
186+
ignore-init-module-imports = true
187+
select = ["F", "E", "W", "C4", "D", "UP", "NPY201"]
194188

195189
# D205: not using summary lines and descriptions, just descriptions
196190
# D401: don't believe enough in imperative mode to make all the changes currently
@@ -226,7 +220,7 @@ exclude = [
226220
# Allow unused variables when underscore-prefixed.
227221
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
228222

229-
[tool.ruff.per-file-ignores]
223+
[tool.ruff.lint.per-file-ignores]
230224
"setup.py" = ["D104"]
231225
"library/__init__.py" = ["D104"]
232226
"library/code_comparison/__init__.py" = ["D104"]
@@ -278,5 +272,5 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
278272
"wombat/windfarm/__init__.py" = ["F401"]
279273
"wombat/windfarm/system/__init__.py" = ["F401"]
280274

281-
[tool.ruff.pydocstyle]
275+
[tool.ruff.lint.pydocstyle]
282276
convention = "numpy"

wombat/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from wombat.core.library import create_library_structure
55

66

7-
__version__ = "0.9.2"
7+
__version__ = "0.9.3"

wombat/core/data_classes.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def check_start_stop_dates(
250250

251251

252252
def valid_hour(
253-
instance: Any, attribute: Attribute, value: int # pylint: disable=W0613
253+
instance: Any,
254+
attribute: Attribute,
255+
value: int, # pylint: disable=W0613
254256
) -> None:
255257
"""Validate that the input is a valid time or null value (-1).
256258
@@ -275,7 +277,9 @@ def valid_hour(
275277

276278

277279
def valid_reduction(
278-
instance, attribute: Attribute, value: int | float # pylint: disable=W0613
280+
instance,
281+
attribute: Attribute,
282+
value: int | float, # pylint: disable=W0613
279283
) -> None:
280284
"""Check to see if the reduction factor is between 0 and 1, inclusive.
281285

wombat/core/post_processor.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,17 @@ def _check_frequency(frequency: str, which: str = "all") -> str:
5353
def _calculate_time_availability(
5454
availability: pd.DataFrame,
5555
by_turbine: bool = False,
56-
turbine_id: list[str] | None = None,
5756
) -> float | np.ndarray:
5857
"""Calculates the availability ratio of the whole timeseries or the whole
5958
timeseries, by turbine.
6059
6160
Parameters
6261
----------
6362
availability : pd.DataFrame
64-
Timeseries array of operating ratios.
63+
Timeseries array of operating ratios for all turbines.
6564
by_turbine : bool, optional
6665
If True, calculates the availability rate of each column, otherwise across the
6766
whole array, by default False.
68-
turbine_id : list[str], optional
69-
A list of turbine IDs that is required if :py:attr:`by_turbine` is ``True``, by
70-
default None.
7167
7268
Returns
7369
-------
@@ -77,8 +73,8 @@ def _calculate_time_availability(
7773
"""
7874
availability = availability > 0
7975
if by_turbine:
80-
return availability[turbine_id].values.sum(axis=0) / availability.shape[0]
81-
return availability.windfarm.values.sum() / availability.windfarm.size
76+
return availability.values.sum(axis=0) / availability.shape[0]
77+
return availability.values.sum() / availability.size
8278

8379

8480
class Metrics:
@@ -375,15 +371,13 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
375371
for sub, val in self.substation_turbine_map.items():
376372
turbine_operations[val["turbines"]] *= self.operations[[sub]].values
377373

378-
hourly = turbine_operations.loc[:, ["windfarm"] + self.turbine_id]
374+
hourly = turbine_operations.loc[:, self.turbine_id]
379375

380376
# TODO: The below should be better summarized as:
381377
# (availability > 0).groupby().sum() / groupby().count()
382378

383379
if frequency == "project":
384-
availability = _calculate_time_availability(
385-
hourly, by_turbine=by_turbine, turbine_id=self.turbine_id
386-
)
380+
availability = _calculate_time_availability(hourly, by_turbine=by_turbine)
387381
if not by_turbine:
388382
return pd.DataFrame([availability], columns=["windfarm"])
389383

@@ -401,7 +395,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
401395
_calculate_time_availability(
402396
hourly[date_time.year == year],
403397
by_turbine=by_turbine,
404-
turbine_id=self.turbine_id,
405398
)
406399
for year in counts.index
407400
]
@@ -414,7 +407,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
414407
_calculate_time_availability(
415408
hourly[date_time.month == month],
416409
by_turbine=by_turbine,
417-
turbine_id=self.turbine_id,
418410
)
419411
for month in counts.index
420412
]
@@ -427,7 +419,6 @@ def time_based_availability(self, frequency: str, by: str) -> pd.DataFrame:
427419
_calculate_time_availability(
428420
hourly[(date_time.year == year) & (date_time.month == month)],
429421
by_turbine=by_turbine,
430-
turbine_id=self.turbine_id,
431422
)
432423
for year, month in counts.index
433424
]

wombat/windfarm/windfarm.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ def _create_wind_farm_map(self) -> None:
345345
downstream=graph.nodes[s_id]["connection"],
346346
)
347347
self.wind_farm_map = WindFarmMap(
348-
substation_map=wind_map, export_cables=export # type: ignore
348+
substation_map=wind_map,
349+
export_cables=export, # type: ignore
349350
)
350351

351352
def finish_setup(self) -> None:

0 commit comments

Comments
 (0)