Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from pyearthtools.pipeline.operation import Operation

from pyearthtools.data.transforms.attributes import SetType
from pyearthtools.utils.decorators import BackwardsCompatibility

T = TypeVar("T", xr.Dataset, xr.DataArray)

Expand Down Expand Up @@ -185,11 +184,7 @@ def apply_func(self, dataset: xr.Dataset) -> xr.Dataset:
return new_ds

def undo_func(self, ds):
return pyearthtools.pipeline.operations.xarray.reshape.coordinate_expand(self._coordinate)(ds)


@BackwardsCompatibility(CoordinateFlatten)
def coordinate_flatten(*args, **kwargs) -> Operation: ...
return pyearthtools.pipeline.operations.xarray.reshape.CoordinateExpand(self._coordinate)(ds)


class CoordinateExpand(Operation):
Expand Down Expand Up @@ -242,8 +237,4 @@ def apply_func(self, dataset: xr.Dataset) -> xr.Dataset | xr.DataArray:
return dataset

def undo_func(self, ds):
return pyearthtools.pipeline.operations.xarray.reshape.coordinate_flatten(self._coordinate)(ds)


@BackwardsCompatibility(CoordinateExpand)
def coordinate_expand(*args, **kwargs) -> Operation: ...
return pyearthtools.pipeline.operations.xarray.reshape.CoordinateFlatten(self._coordinate)(ds)
33 changes: 0 additions & 33 deletions packages/utils/src/pyearthtools/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from __future__ import annotations

import functools
import warnings
from typing import Any, Callable, TypeVar

C = TypeVar("C", bound=Callable[..., Any])
Expand Down Expand Up @@ -92,35 +91,3 @@ def wrapper(*args, **kwargs):
return wrapper

return internal_function


def BackwardsCompatibility(new_func: C) -> Callable[[C], C]:
"""
Allows for the renaming of a functionality, and subsequent backwards compatilbility.

Will warn about deprecation on use.

Args:
new_func:
New function to point to instead

Example:
>>> def new_func(): # New function name
...
>>> @BackwardsCompatibility(new_func)
>>> def old_func(*a, **kw):
...

"""

def decorator(func: C) -> C:
def wrapped(*args, **kwargs):
warnings.warn(
f"{func.__name__} has been removed in favour of {new_func.__name__}, please switch over.",
DeprecationWarning,
)
return new_func(*args, **kwargs)

return wrapped

return decorator