ads.common.decorator package

Submodules

ads.common.decorator.argument_to_case module

The module that provides the decorator helping to convert function arguments to specific case (lower/upper).

Examples

>>> @argument_to_case("lower", ["name"])
... def test_function(name: str, last_name: str)
...     print(name)
...
>>> test_function("myname", "mylastname")
... MYNAME
class ads.common.decorator.argument_to_case.ArgumentCase(value)[source]

Bases: Enum

An enumeration.

LOWER = 'lower'
UPPER = 'upper'
ads.common.decorator.argument_to_case.argument_to_case(case: ArgumentCase, arguments: List[str])[source]

The decorator helping to convert function arguments to specific case.

Parameters:
  • case (ArgumentCase) – The case to convert specific arguments.

  • arguments (List[str]) – The list of arguments to convert to specific case.

Examples

>>> @argument_to_case("lower", ["name"])
... def test_function(name: str, last_name: str)
...     print(name)
...
>>> test_function("myname", "mylastname")
... MYNAME

ads.common.decorator.deprecate module

exception ads.common.decorator.deprecate.NotSupportedError[source]

Bases: Exception

class ads.common.decorator.deprecate.TARGET_TYPE(value)[source]

Bases: Enum

An enumeration.

ATTRIBUTE = 'Attribute'
CLASS = 'Class'
METHOD = 'Method'
ads.common.decorator.deprecate.deprecated(deprecated_in: str | None = None, removed_in: str | None = None, details: str | None = None, target_type: str | None = None, raise_error: bool = False)[source]

This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.

Parameters:
  • deprecated_in (str) – Version of ADS where this function deprecated.

  • removed_in (str) – Future version where this function will be removed.

  • details (str) – More information to be shown.

ads.common.decorator.runtime_dependency module

The module that provides the decorator helping to add runtime dependencies in functions.

Examples

>>> @runtime_dependency(module="pandas", short_name="pd")
... def test_function()
...     print(pd)
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df")
... def test_function()
...     print(df)
>>> @runtime_dependency(module="pandas", short_name="pd")
... @runtime_dependency(module="pandas", object="DataFrame", short_name="df")
... def test_function()
...     print(df)
...     print(pd)
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df", install_from="ads[optional]")
... def test_function()
...     pass
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df", err_msg="Custom error message.")
... def test_function()
...     pass
class ads.common.decorator.runtime_dependency.OptionalDependency[source]

Bases: object

BDS = 'oracle-ads[bds]'
BOOSTED = 'oracle-ads[boosted]'
DATA = 'oracle-ads[data]'
FEATURE_STORE = 'oracle-ads[feature-store]'
FEATURE_STORE_MARKETPLACE = 'oracle-ads[feature-store-marketplace]'
FORECAST = 'oracle-ads[forecast]'
GEO = 'oracle-ads[geo]'
GRAPHVIZ = 'oracle-ads[graphviz]'
HUGGINGFACE = 'oracle-ads[huggingface]'
LABS = 'oracle-ads[labs]'
MLM_INSIGHTS = 'oracle-ads[mlm_insights]'
MYSQL = 'oracle-ads[mysql]'
NOTEBOOK = 'oracle-ads[notebook]'
ONNX = 'oracle-ads[onnx]'
OPCTL = 'oracle-ads[opctl]'
OPTUNA = 'oracle-ads[optuna]'
PII = 'oracle-ads[pii]'
PYTORCH = 'oracle-ads[torch]'
SPARK = 'oracle-ads[spark]'
TENSORFLOW = 'oracle-ads[tensorflow]'
TEXT = 'oracle-ads[text]'
VIZ = 'oracle-ads[viz]'
ads.common.decorator.runtime_dependency.runtime_dependency(module: str, short_name: str = '', object: str | None = None, install_from: str | None = None, err_msg: str = '', is_for_notebook_only=False)[source]

The decorator which is helping to add runtime dependencies to functions.

Parameters:
  • module (str) – The module name to be imported.

  • short_name ((str, optional). Defaults to empty string.) – The short name for the imported module.

  • object ((str, optional). Defaults to None.) – The name of the object to be imported. Can be a function or a class, or any variable provided by module.

  • install_from ((str, optional). Defaults to None.) – The parameter helping to answer from where the required dependency can be installed.

  • err_msg ((str, optional). Defaults to empty string.) – The custom error message.

  • is_for_notebook_only ((bool, optional). Defaults to False.) – If the value of this flag is set to True, the dependency will be added only in case when the current environment is a jupyter notebook.

Raises:

Examples

>>> @runtime_dependency(module="pandas", short_name="pd")
... def test_function()
...     print(pd)
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df")
... def test_function()
...     print(df)
>>> @runtime_dependency(module="pandas", short_name="pd")
... @runtime_dependency(module="pandas", object="DataFrame", short_name="df")
... def test_function()
...     print(df)
...     print(pd)
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df", install_from="ads[optional]")
... def test_function()
...     pass
>>> @runtime_dependency(module="pandas", object="DataFrame", short_name="df", err_msg="Custom error message.")
... def test_function()
...     pass

ads.common.decorator.utils module

class ads.common.decorator.utils.class_or_instance_method[source]

Bases: classmethod

Converts a function to be a class method or an instance depending on how it is called at runtime.

To declare a class method, use this idiom:

class C:

@classmethod def f(obj, *args, **kwargs):

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). If it is called on the class C.f(), the first argument (obj) will be the class (aka. cls). If it is called on the instance C().f(), the first argument (obj) will be the instance (aka. self).

Module contents