Skip to content

Commit

Permalink
deprecate debug event argument (#1569)
Browse files Browse the repository at this point in the history
## Description

deprecate `debug_event` argument.

## Changes

- adds a `deprecate_argument` decorator to issue a warning if a
deprecated keyword argument is used.


- [ ] I have reviewed the [Guidelines for Contributing](CONTRIBUTING.md)
and the [Code of Conduct](CODE_OF_CONDUCT.md).
  • Loading branch information
richard-rogers authored Oct 1, 2024
1 parent 7660542 commit 89fec66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/whylogs/api/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
ModelPerformanceMetrics,
)
from whylogs.core.stubs import pd
from whylogs.core.utils import deprecated_argument

diagnostic_logger = logging.getLogger(__name__)

Loggable = Union["pd.DataFrame", List[Dict[str, Any]]]


@deprecated_argument("debug_event")
def log(
obj: Any = None,
*,
Expand Down
3 changes: 2 additions & 1 deletion python/whylogs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
get_distribution_metrics,
is_probably_unique,
)
from .utils import deprecated, deprecated_alias, ensure_timezone
from .utils import deprecated, deprecated_alias, deprecated_argument, ensure_timezone

__ALL__ = [ #
read_delimited_protobuf,
Expand All @@ -13,6 +13,7 @@
is_probably_unique,
get_cardinality_estimate,
deprecated_alias,
deprecated_argument,
deprecated,
ensure_timezone, #
]
17 changes: 16 additions & 1 deletion python/whylogs/core/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import functools
import warnings
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, Optional
from urllib.parse import urlparse

from urllib3 import util
Expand Down Expand Up @@ -32,6 +32,21 @@ def wrapper(*args, **kwargs):
return deprecated_decorator


def deprecated_argument(arg_name: str, message: Optional[str] = None):
def deprecated_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if arg_name in kwargs:
warnings.warn(
f"Argument {arg_name} is deprecated, {message if message else 'it will be removed in the next major version of whylogs'}."
)
return func(*args, **kwargs)

return wrapper

return deprecated_decorator


def rename_kwargs(func_name: str, kwargs: Dict[str, Any], aliases: Dict[str, str]) -> None:
for alias, new in aliases.items():
if alias in kwargs:
Expand Down

0 comments on commit 89fec66

Please sign in to comment.