Skip to content

refactor(collection)!: consolidate the DatasetCollection constructor API - #951

Merged
MAfarrag merged 13 commits into
mainfrom
refactor/dataset-collection
Aug 10, 2026
Merged

refactor(collection)!: consolidate the DatasetCollection constructor API#951
MAfarrag merged 13 commits into
mainfrom
refactor/dataset-collection

Conversation

@MAfarrag

@MAfarrag MAfarrag commented Aug 9, 2026

Copy link
Copy Markdown
Member

Description

Consolidates the DatasetCollection constructor surface, adds a Grid value object, and completes the from_point
grid match. Plus docs and tests.

  • Rename DatasetCollection.create_cube -> from_dataset (param src -> dataset) to align with the from_* reader
    family and disambiguate it from Dataset.create; hard rename, no deprecation alias.
  • Add Grid, a frozen dataclass exported from pyramids.dataset whose __post_init__ enforces the target-grid mode
    invariants (like xor the crs/resolution/bounds trio, the trio all-or-nothing, and anchor).
  • Group from_stac's five target-grid kwargs (like, crs, resolution, bounds, anchor) into a single
    grid: Grid | None parameter, dropping it from 14 to 10 params and mirroring odc.stac.load's geobox= grouping.
  • Resample from_point cubes onto the exact edge_sizexedge_size local-UTM grid via an internally built Grid,
    closing the documented native-grid gap.
  • Docs: add classDiagram views of the constructors/properties, a pre-commit hooks how-to, and STAC/lazy tutorial updates.
  • Tests: add a dedicated Grid unit suite; migrate the grid-match tests.

Issues

Relates to #757 (same python:S107 parameter-count reduction, applied to from_stac).

Type of change

Check relevant points.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Targeted suites run against the branch (MPLBACKEND=Agg):

pytest tests/dataset/test_grid.py tests/dataset/stac tests/dataset/collection tests/e2e/test_e2e_workflows.py
  • tests/dataset/test_grid.py — dedicated Grid unit suite (construction, invariants, is_empty, frozen, equality)
  • tests/dataset/stac/test_from_stac_grid.py — resolver + from_stac grid match via Grid
  • tests/dataset/collection/test_from_point.py — asserts the forwarded Grid (local UTM crs/resolution/bounds)
  • Grid doctests pass; mypy clean on the changed source; pre-commit (ruff/bandit/format) green; SonarCloud clean

Checklist:

  • updated version number in pyproject.toml.
  • added changes to History.rst.
  • updated the latest version in README file.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • documentation are updated.

BREAKING CHANGE: DatasetCollection.create_cube is renamed to from_dataset, and from_stac no longer accepts
like/crs/resolution/bounds/anchor — pass grid=Grid(...) instead.

Rename the in-memory template factory create_cube -> create (dropping the
legacy 'cube'/datacube naming), align its parameter dataset_length ->
time_length with the constructor, and fix the broken docstring. Update all
call sites in src docstrings, tests, and docs. No deprecated alias.

BREAKING CHANGE: DatasetCollection.create_cube is removed; use
DatasetCollection.create(src, time_length=...) instead.
Align the in-memory template factory with the from_* reader family and
avoid the name collision with Dataset.create: create -> from_dataset
(same (src, time_length) signature). Update all call sites in the src
docstrings, tests, and docs. Dataset.create is unaffected.

BREAKING CHANGE: DatasetCollection.create is renamed to from_dataset; use
DatasetCollection.from_dataset(src, time_length=...).
Match the from_* reader docstring style: add two +SKIP examples showing
the in-memory scaffold (time_length, files is None) and a See Also
cross-referencing from_files/from_zarr/from_stac.
@MAfarrag MAfarrag changed the title Refactor/dataset collection refactor(collection)!: rename DatasetCollection.create_cube to from_dataset Aug 9, 2026
Add an 'API at a glance' section to the collection reference with two
mermaid classDiagram blocks: one for the from_* constructors (all
classmethods, returning DatasetCollection) and one for the public
properties, with notes on settable vs read-only and nullable fields.
…fy from_stac bbox vs bounds

Rename the from_dataset template parameter 'src' to the more descriptive
'dataset' (echoes the method name and its type); all call sites pass it
positionally, so no caller is affected. Update the classDiagram signature
to match.

Sharpen the from_stac docstring so the two (minx, miny, maxx, maxy) tuples
are no longer confusable: bbox is the input filter in lon/lat that selects
which STAC items are read, while bounds is the output grid extent in the
target CRS. Note the divergence from odc-stac (where bbox sets the output
extent).
Document the pre-commit setup: install, triggering (all files, a subset,
a single hook by id), the full hook catalogue with speed tiers, and how
to skip hooks via SKIP / --no-verify (with the CI skip set). Add it to
the How-to nav.
… dataclass

Collapse from_stac's five target-grid keyword arguments (like, crs,
resolution, bounds, anchor) into a single grid: Grid | None parameter.
Grid is a frozen dataclass whose __post_init__ enforces the mode
invariants (like xor the crs/resolution/bounds trio, the trio being
all-or-nothing, and the anchor value) previously checked inside
_resolve_target_grid. This drops from_stac from 14 to 10 parameters and
mirrors odc.stac.load's geobox= grouping. Grid is exported from
pyramids.dataset; _resolve_target_grid now takes a Grid and only builds
the template.

BREAKING CHANGE: DatasetCollection.from_stac no longer accepts
like/crs/resolution/bounds/anchor keyword arguments; pass grid=Grid(...)
instead, e.g. grid=Grid(like=ds) or grid=Grid(crs=32633, resolution=10,
bounds=(...)).
…grid

Extend the Grid mechanism to from_point: it now builds a
Grid(crs=<local UTM>, resolution, bounds=<resolution-snapped UTM AOI>)
and forwards it to from_stac, so every timestep is resampled and
co-registered onto the exact edge_size x edge_size local-UTM grid the
AOI defines. Previously the cube was left on the matched assets' native
grid -- the documented 'not yet' PC-2 gap.

_point_aoi_bbox now also returns the UTM AOI square it already computed
(and discarded); from_point uses it as the Grid bounds. Tests assert the
forwarded Grid carries the local UTM crs/resolution/bounds.
Add tests/dataset/test_grid.py covering Grid construction, the mode
invariants (like xor the crs/resolution/bounds trio, the trio being
all-or-nothing, and the anchor check), the is_empty property, frozen
immutability, and equality -- every __post_init__ branch. Remove the now
redundant TestGrid class from test_from_stac_grid.py (superseded by the
dedicated module test), keeping its resolver and from_stac integration
tests.
@MAfarrag MAfarrag changed the title refactor(collection)!: rename DatasetCollection.create_cube to from_dataset refactor(collection)!: constructor API cleanup — from_dataset, Grid grouping, from_point grid Aug 9, 2026
Build the valid Grid before the pytest.raises block in
test_oversize_grid_raises so only _resolve_target_grid's OOM guard can
throw inside it -- resolves the SonarCloud python:S5778 'one throwing
call per exception test' finding.
@sonarqubecloud

sonarqubecloud Bot commented Aug 9, 2026

Copy link
Copy Markdown

@MAfarrag MAfarrag changed the title refactor(collection)!: constructor API cleanup — from_dataset, Grid grouping, from_point grid refactor(collection)!: consolidate the DatasetCollection constructor API Aug 9, 2026
@MAfarrag
MAfarrag merged commit 541d3dc into main Aug 10, 2026
47 of 48 checks passed
@MAfarrag
MAfarrag deleted the refactor/dataset-collection branch August 10, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant