Skip to content

Commit

Permalink
Move all deprecated functions to deprecated.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Sep 27, 2023
1 parent b896bd3 commit 0b9e421
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 44 deletions.
3 changes: 2 additions & 1 deletion pysr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from . import sklearn_monkeypatch
from .deprecated import best, best_callable, best_row, best_tex, pysr
from .export_jax import sympy2jax
from .export_torch import sympy2torch
from .feynman_problems import FeynmanProblem, Problem
from .julia_helpers import install
from .sr import PySRRegressor, best, best_callable, best_row, best_tex, pysr
from .sr import PySRRegressor
from .version import __version__

__all__ = [
Expand Down
54 changes: 54 additions & 0 deletions pysr/deprecated.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
"""Various functions to deprecate features."""
import warnings


def pysr(X, y, weights=None, **kwargs): # pragma: no cover
from .sr import PySRRegressor

warnings.warn(
"Calling `pysr` is deprecated. "
"Please use `model = PySRRegressor(**params); "
"model.fit(X, y)` going forward.",
FutureWarning,
)
model = PySRRegressor(**kwargs)
model.fit(X, y, weights=weights)
return model.equations_


def best(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best` has been deprecated. "
"Please use the `PySRRegressor` interface. "
"After fitting, you can return `.sympy()` "
"to get the sympy representation "
"of the best equation."
)


def best_row(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_row` has been deprecated. "
"Please use the `PySRRegressor` interface. "
"After fitting, you can run `print(model)` to view the best equation, "
"or "
"`model.get_best()` to return the best equation's "
"row in `model.equations_`."
)


def best_tex(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_tex` has been deprecated. "
"Please use the `PySRRegressor` interface. "
"After fitting, you can return `.latex()` to "
"get the sympy representation "
"of the best equation."
)


def best_callable(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_callable` has been deprecated. Please use the `PySRRegressor` "
"interface. After fitting, you can use "
"`.predict(X)` to use the best callable."
)


def make_deprecated_kwargs_for_pysr_regressor():
Expand Down
2 changes: 1 addition & 1 deletion pysr/feynman_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from .sr import best, pysr
from .deprecated import best, pysr

PKG_DIR = Path(__file__).parents[1]
FEYNMAN_DATASET = PKG_DIR / "datasets" / "FeynmanEquations.csv"
Expand Down
42 changes: 0 additions & 42 deletions pysr/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@
already_ran = False


def pysr(X, y, weights=None, **kwargs): # pragma: no cover
warnings.warn(
"Calling `pysr` is deprecated. "
"Please use `model = PySRRegressor(**params); model.fit(X, y)` going forward.",
FutureWarning,
)
model = PySRRegressor(**kwargs)
model.fit(X, y, weights=weights)
return model.equations_


def _process_constraints(binary_operators, unary_operators, constraints):
constraints = constraints.copy()
for op in unary_operators:
Expand Down Expand Up @@ -181,37 +170,6 @@ def _check_assertions(
)


def best(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best` has been deprecated. Please use the `PySRRegressor` interface. "
"After fitting, you can return `.sympy()` to get the sympy representation "
"of the best equation."
)


def best_row(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_row` has been deprecated. Please use the `PySRRegressor` interface. "
"After fitting, you can run `print(model)` to view the best equation, or "
"`model.get_best()` to return the best equation's row in `model.equations_`."
)


def best_tex(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_tex` has been deprecated. Please use the `PySRRegressor` interface. "
"After fitting, you can return `.latex()` to get the sympy representation "
"of the best equation."
)


def best_callable(*args, **kwargs): # pragma: no cover
raise NotImplementedError(
"`best_callable` has been deprecated. Please use the `PySRRegressor` "
"interface. After fitting, you can use `.predict(X)` to use the best callable."
)


# Class validation constants
VALID_OPTIMIZER_ALGORITHMS = ["NelderMead", "BFGS"]

Expand Down

0 comments on commit 0b9e421

Please sign in to comment.