Repository navigation
Conversation
soxofaan
left a comment
There was a problem hiding this comment.
some further finetuning suggestions
| ) | ||
| ] | ||
| else: | ||
| assert caplog.records == [] |
There was a problem hiding this comment.
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 == []
There was a problem hiding this comment.
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.
|
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 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 iswhat do you think? |
|
Makes sense, I like that better than the warning. I'll reuse the existing |
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.
8d313c8 to
986afd0
Compare
|
went with the existing |
Fixes #796.
add_dimension(name="bands", label=...)created a dimension with typeother, which breaks later on when a band dimension is expected.DataCube.add_dimension()now picks the type from the name whentypeisn't given:bands,x/y/zas spatial,t/time/temporalas temporal,geometryas geometry. Other names behave as before. Passingtypeexplicitly still wins, includingNoneor"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.