Skip to content

Commit 948f928

Browse files
committed
Warn when not explicitly specifying dimension in apply_dimension #774
1 parent 6da65a2 commit 948f928

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
- `DataCube.apply_dimension()`: not explicitly specifying the `dimension` argument is deprecated and will trigger warnings ([#774](https://github.com/Open-EO/openeo-python-client/issues/774))
15+
1416
### Removed
1517

1618
### Fixed

openeo/rest/datacube.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ def apply_dimension(
13701370
# TODO: drop None default of process (when `code` and `runtime` args can be dropped)
13711371
process: Union[str, typing.Callable, UDF, PGNode] = None,
13721372
version: Optional[str] = None,
1373-
# TODO: dimension has no default (per spec)?
1374-
dimension: str = "t",
1373+
# TODO #774 fully drop default value for dimension after deprecation period
1374+
dimension: str = _UNSET,
13751375
target_dimension: Optional[str] = None,
13761376
context: Optional[dict] = None,
13771377
) -> DataCube:
@@ -1426,6 +1426,9 @@ def apply_dimension(
14261426
of using an :py:class:`UDF <openeo.rest._datacube.UDF>` object in the ``process`` argument.
14271427
See :ref:`old_udf_api` for more background about the changes.
14281428
1429+
.. versionchanged:: 0.42.0
1430+
Not explicitly specifying the ``dimension`` argument is deprecated and will trigger warnings.
1431+
The original fallback value "t" is still in place, but that will be removed in a future version.
14291432
"""
14301433
# TODO #137 #181 #312 remove support for code/runtime/version
14311434
if runtime or (isinstance(code, str) and "\n" in code) or version:
@@ -1446,6 +1449,17 @@ def apply_dimension(
14461449
process = build_child_callback(
14471450
process=process, parent_parameters=["data", "context"], connection=self.connection
14481451
)
1452+
1453+
if dimension is _UNSET:
1454+
# TODO #774 fully drop this dimension fallback value after deprecation period
1455+
warnings.warn(
1456+
"Using `DataCube.apply_dimension()` without explicit `dimension` argument is deprecated and will become invalid in a future version. "
1457+
"Falling back on dimension 't'.",
1458+
category=UserDeprecationWarning,
1459+
stacklevel=2,
1460+
)
1461+
dimension = "t"
1462+
14491463
arguments = {
14501464
"data": THIS,
14511465
"process": process,

tests/rest/datacube/test_datacube.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,29 @@ def test_apply_dimension(connection, requests_mock):
992992
s22.apply_dimension(dimension='wut', code="subtract_mean")
993993

994994

995+
def test_apply_dimension_unspecified_dimension(s2cube, dummy_backend, recwarn):
996+
s2cube.apply_dimension("cumsum").create_job()
997+
assert dummy_backend.get_pg(process_id="apply_dimension") == {
998+
"process_id": "apply_dimension",
999+
"arguments": {
1000+
"data": {"from_node": "loadcollection1"},
1001+
"dimension": "t",
1002+
"process": {
1003+
"process_graph": {
1004+
"cumsum1": {
1005+
"arguments": {"data": {"from_parameter": "data"}},
1006+
"process_id": "cumsum",
1007+
"result": True,
1008+
}
1009+
}
1010+
},
1011+
},
1012+
}
1013+
assert str(recwarn.pop()) == dirty_equals.IsStr(
1014+
regex=".*UserDeprecationWarning.*apply_dimension.*without explicit.*dimension.*argument.*is deprecated.*filename.*/test_datacube.py.*"
1015+
)
1016+
1017+
9951018
def test_download_path_str(connection, requests_mock, tmp_path):
9961019
requests_mock.get(API_URL + "/collections/S2", json={})
9971020
requests_mock.post(API_URL + '/result', content=b"tiffdata")

0 commit comments

Comments
 (0)