Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Releases from v0.4.0 onwards are now archived with a DOI. A badge at the top of the README shows the DOI of the last release. ([@brews](https://github.com/brews), [PR#94](https://github.com/ClimateImpactLab/isku/pull/94))

### Changed

- Stricter type checking from ruff/ty. ([@brews](https://github.com/brews), [PR#125](https://github.com/ClimateImpactLab/isku/pull/125))

## [0.4.0] - 2026-07-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion prek.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hooks = [

[[repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.15.12"
rev = "v0.16.6"
hooks = [
{ id = "ruff-check", args = ["--fix", "--show-fixes"] },
{ id = "ruff-format" },
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tests = [
"numpy>=2.4.4",
"pytest>=9.0.3",
"pytest-cov>=7.1.0",
"ruff>=0.15.12",
"ruff>=0.16.0",
"ty>=0.0.35",
]
docs = ["mkdocstrings[python]>=1.0.4", "zensical>=0.0.41"]
Expand All @@ -30,6 +30,7 @@ build-backend = "uv_build"

[tool.ruff.lint]
extend-select = [
"ANN",
"YTT", # flake8-2020
"B", # flake8-bugbear
"C4", # flake8-comprehensions
Expand All @@ -51,10 +52,17 @@ extend-select = [
"FURB", # refurb
"RUF",
]
preview = true

[tool.ruff.lint.isort]
known-first-party = ["isku"]

[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

[tool.ty.rules]
dynamic-function-decorator-return = "error"
missing-type-argument = "error"
possibly-unresolved-reference = "warn"
unsound-return-statement = "error"
2 changes: 1 addition & 1 deletion src/isku/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class GridWeightingRegions(RegionExtractor):
RegionExtractor: Protocol for regionalizing, or extracting regions from a dataset.
"""

def __init__(self, weights: xr.Dataset):
def __init__(self, weights: xr.Dataset) -> None:
target_variables = ("lat", "lon", "weight", "region")
missing_variables = [v for v in target_variables if v not in weights.variables]
if missing_variables:
Expand Down
8 changes: 4 additions & 4 deletions tests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
import isku


def test_basic_projection():
def test_basic_projection() -> None:
"""
Basic test running build_projection_template() with project().
"""
predictors = xr.Dataset({"foobar": (["idx"], [0, 0, 0])})
params = xr.Dataset({"ni": (["idx"], [1, 2, 3])})
expected = xr.Dataset({"impact": (["idx"], [13, 14, 15])})

def _pre(x):
def _pre(x: xr.Dataset) -> xr.Dataset:
out = xr.Dataset()
out["foobar"] = x["foobar"] + 1
out["ni"] = x["ni"]
return out

def _post(x):
def _post(x: xr.Dataset) -> xr.Dataset:
return x[["impact"]] + 10

def _model(x):
def _model(x: xr.Dataset) -> xr.Dataset:
return (x["foobar"] * 2 + x["ni"]).to_dataset(name="impact")

test_impact_model = isku.build_projection_template(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import isku


def test_extract_regions():
def test_extract_regions() -> None:
"""
Create simple extraction template and test basic region extraction.
"""
Expand All @@ -17,10 +17,10 @@ def test_extract_regions():

# Each of the transformation steps should add to the variable.
# We'll know something basic is off if it doesn't add to `expected`.
def _pre(x):
def _pre(x: xr.Dataset) -> xr.Dataset:
return x[["variable1"]] + 1

def _post(x):
def _post(x: xr.Dataset) -> xr.Dataset:
return x[["variable1"]] + 10

test_transform = isku.build_extraction_template(pre=_pre, post=_post)
Expand All @@ -30,7 +30,7 @@ class FakeRegionalization(isku.RegionExtractor):
Toy implementation of the RegionExtractor protocol
"""

def extract_regions(self, ds):
def extract_regions(self, ds: xr.Dataset) -> xr.Dataset: # ruff: ignore[no-self-use]
return ds[["variable1"]] + 2.5

output = isku.extract_regions(
Expand All @@ -42,7 +42,7 @@ def extract_regions(self, ds):
xr.testing.assert_allclose(output, expected)


def test_gridweightingregions_region_extraction():
def test_gridweightingregions_region_extraction() -> None:
"""
Basic test calling GridWeightingRegions for regionalization with the RegionExtractor protocol.
"""
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_gridweightingregions_region_extraction():
xr.testing.assert_allclose(actual, expected)


def test_gridweightingregions_extract_regions_with_extradim():
def test_gridweightingregions_extract_regions_with_extradim() -> None:
"""
Basic GridWeightingRegions regionalization test, but if input data has extra time dim.
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
from isku import build_projection_template, project


def test_basic_projection():
def test_basic_projection() -> None:
"""
Basic test running build_projection_template() with project().
"""
predictors = xr.Dataset({"foobar": (["idx"], [0, 0, 0])})
params = xr.Dataset({"ni": (["idx"], [1, 2, 3])})
expected = xr.Dataset({"impact": (["idx"], [13, 14, 15])})

def _pre(x):
def _pre(x: xr.Dataset) -> xr.Dataset:
out = xr.Dataset()
out["foobar"] = x["foobar"] + 1
out["ni"] = x["ni"]
return out

def _post(x):
def _post(x: xr.Dataset) -> xr.Dataset:
return x[["impact"]] + 10

def _model(x):
def _model(x: xr.Dataset) -> xr.Dataset:
return (x["foobar"] * 2 + x["ni"]).to_dataset(name="impact")

test_impact_model = build_projection_template(
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.