Skip to content

Commit

Permalink
Add deprecation for moved functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic committed Jun 11, 2024
1 parent 29b42ca commit f90f817
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
dataframe in experimental representation instead of two separate dataframes in
computational representation

### Deprecated
- `add_fake_results` and `add_parameter_noise` have been moved to the simulation package

## [0.9.1] - 2024-06-04
### Changed
Expand Down
27 changes: 27 additions & 0 deletions baybe/utils/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
import warnings
from collections.abc import Iterator, Sequence
from typing import TYPE_CHECKING, overload

Expand All @@ -19,6 +20,32 @@
_logger = logging.getLogger(__name__)


def add_fake_results(*args, **kwargs):
"""Deprecated. Use ``baybe.simulation.lookup.add_fake_results`` instead.""" # noqa: D401
from baybe.simulation.lookup import add_fake_results as moved_fn

warnings.warn(
"The function 'add_fake_results' has been moved. "
"Please import it from 'baybe.simulation.lookup' instead.",
DeprecationWarning,
)

moved_fn(*args, **kwargs)


def add_parameter_noise(*args, **kwargs):
"""Deprecated. Use ``baybe.simulation.utils.add_parameter_noise`` instead.""" # noqa: D401
from baybe.simulation.utils import add_parameter_noise as moved_fn

warnings.warn(
"The function 'add_parameter_noise' has been moved. "
"Please import it from 'baybe.simulation.utils' instead.",
DeprecationWarning,
)

moved_fn(*args, **kwargs)


@overload
def to_tensor(df: pd.DataFrame) -> Tensor:
...
Expand Down
20 changes: 20 additions & 0 deletions tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from unittest.mock import Mock

import pandas as pd
import pytest

from baybe import Campaign
Expand All @@ -11,6 +12,7 @@
from baybe.objective import Objective as OldObjective
from baybe.objectives.base import Objective as NewObjective
from baybe.objectives.desirability import DesirabilityObjective
from baybe.parameters.numerical import NumericalDiscreteParameter
from baybe.recommenders.meta.sequential import TwoPhaseMetaRecommender
from baybe.recommenders.pure.bayesian import SequentialGreedyRecommender
from baybe.recommenders.pure.nonpredictive.sampling import (
Expand Down Expand Up @@ -188,3 +190,21 @@ def test_deprecated_acqf_keyword(acqf):
"""Using the deprecated keyword raises an error."""
with pytest.raises(DeprecationError):
SequentialGreedyRecommender(acquisition_function_cls="qEI")


def test_moved_add_fake_results():
"""Using the function imported from the old location raises a warning."""
with pytest.warns(DeprecationWarning):
from baybe.utils.dataframe import add_fake_results

add_fake_results(pd.DataFrame(), [NumericalTarget("target", "MAX")])


def test_moved_add_parameter_noise():
"""Using the function imported from the old location raises a warning."""
with pytest.warns(DeprecationWarning):
from baybe.utils.dataframe import add_parameter_noise

add_parameter_noise(
pd.DataFrame({"p": [0]}), [NumericalDiscreteParameter("p", [0, 1])]
)

0 comments on commit f90f817

Please sign in to comment.