Skip to content

fix: infer add_dimension() type from common dimension names - #963

Open
minaskar wants to merge 1 commit into
Open-EO:masterfrom
minaskar:issue-796-add-dimension-warning
Open

minaskar wants to merge 1 commit into
Open-EO:masterfrom
minaskar:issue-796-add-dimension-warning

Conversation

@minaskar

@minaskar minaskar commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #796.

add_dimension(name="bands", label=...) created a dimension with type other, which breaks later on when a band dimension is expected.

DataCube.add_dimension() now picks the type from the name when type isn't given: bands, x/y/z as spatial, t/time/temporal as temporal, geometry as geometry. Other names behave as before. Passing type explicitly still wins, including None or "other", and whatever gets used is also passed to the metadata. Logs at INFO when it infers something.

Full suite passes on current master: 3099 passed, 9 skipped.

@minaskar
minaskar requested a review from soxofaan October 28, 2026 13:38
Comment thread openeo/rest/datacube.py Resolved
Comment thread openeo/rest/datacube.py Resolved
Comment thread tests/rest/datacube/test_datacube100.py Resolved

@soxofaan soxofaan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some further finetuning suggestions

Comment thread CHANGELOG.md Resolved
)
]
else:
assert caplog.records == []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test parameterization and test logic are a bit hard to follow (especially with the mix of several kinds of names and types)

I would just do something like

pytest.mark.parametrize(
    ["name", "add_dimension_kwargs", "expected_suggestion"],
    [
        ("bands", {}, "bands"),
        ("bands", {"type": "bands"}, None),
        ("x", {}, "spatial"),
        ("x", {"type": "spatial"}, None),
         ...
def test_add_dimension_type_warning....
    ...
        result = cube.add_dimension(name=name, label="coh_VV_amp", **add_dimension_kwargs)

    if expected_suggestion:
        assert caplog.record_tuples == [
            ...
             f"Pass type={expected_suggestion!r}...
    else:
        assert caplog.records == []

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. metadata checks ended up in a separate test, test collection metadata already has x/y/t so those names can't be added there. also removed expected_suggestion, there's no suggestion anymore, just the INFO log line.

@soxofaan

Copy link
Copy Markdown
Member

more generally, I think we can take this a step further, avoid the warning at all and just set the correct type automatically based on name when type is omitted (by default).

along the lines of

# internal sentinel object to trigger automatic handling of some given feature
_AUTO = object()

def add_dimension(name: str, label: str, type = _AUTO):
    if type is _AUTO:
        type = {"x": "spatial", ....}.get(name)
    # explicitly passing `None` or "other" are still allowed and passed through as is

what do you think?

@minaskar

Copy link
Copy Markdown
Author

Makes sense, I like that better than the warning. I'll reuse the existing _UNSET sentinel and drop the warning. Should there be a log.info/log.debug when the type gets filled in automatically, so it can be traced? Or should it stay silent?

@soxofaan

Copy link
Copy Markdown
Member

Should there be a log.info/log.debug when the type gets filled in automatically, so it can be traced?

adding an info log makes sense indeed.

DataCube.add_dimension() now infers the dimension type from common dimension names ("bands", "x"/"y"/"z", "t"/"time"/"temporal", "geometry") when `type` is not given, instead of silently adding an "other" dimension (Open-EO#796). An explicitly given `type` (including `None` or "other") still takes precedence.

The inferred type is used for both the process graph and the cube metadata, so they stay consistent. Inference is logged at INFO level.
@minaskar
minaskar force-pushed the issue-796-add-dimension-warning branch from 8d313c8 to 986afd0 Compare November 4, 2026 09:10
@minaskar

minaskar commented Nov 4, 2026

Copy link
Copy Markdown
Author

went with the existing _UNSET. explicit None/"other" still pass through, unknown names behave as before. added z too since metadata now picks the first free x/y/z axis. info log is in.

@minaskar minaskar changed the title fix: warn when adding a bands dimension without an explicit type fix: infer add_dimension() type from common dimension names Nov 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add_dimension: infer 'type' from name?

2 participants