Skip to content

Require dimension arg in DataCube.apply_dimension #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- `DataCube.apply_dimension()`: explicitly specifying the `dimension` argument is now mandatory. The old default (dimension "t") was unnecessarily opinionated and causing confusion about how the process handles dimensions. ([#774](https://github.com/Open-EO/openeo-python-client/issues/774))

### Removed

### Fixed
Expand Down
23 changes: 19 additions & 4 deletions openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,14 +1366,14 @@ def aggregate_spatial_window(
def apply_dimension(
self,
code: Optional[str] = None,
runtime=None,
*,
# TODO: drop None default of process (when `code` and `runtime` args can be dropped)
process: Union[str, typing.Callable, UDF, PGNode] = None,
version: Optional[str] = None,
# TODO: dimension has no default (per spec)?
dimension: str = "t",
dimension: str,
target_dimension: Optional[str] = None,
context: Optional[dict] = None,
runtime: Optional[str] = None,
version: Optional[str] = None,
) -> DataCube:
"""
Applies a process to all pixel values along a dimension of a raster data cube. For example,
Expand Down Expand Up @@ -1426,6 +1426,21 @@ def apply_dimension(
of using an :py:class:`UDF <openeo.rest._datacube.UDF>` object in the ``process`` argument.
See :ref:`old_udf_api` for more background about the changes.

.. versionchanged:: 0.42.0
Argument ``dimension`` is mandatory now.
It used to have default value "t" but that was overly opinionated
and causing confusion about how dimensions are handled.

As related side-effect, and as further deprecation of the old ``code``/``runtime``/``version`` API,
at most one positional argument is allowed now.
This argument still has its original name ``code``,
but it's likely it will be renamed to ``process`` in the future.
For optimal future (and backward) compatibility,
it is recommended to always use keyword arguments,
e.g. with at least ``process`` and ``dimension``:

.. code-block:: python
cube.apply_dimension(process=..., dimension=...)
"""
# TODO #137 #181 #312 remove support for code/runtime/version
if runtime or (isinstance(code, str) and "\n" in code) or version:
Expand Down