diff --git a/pysr/__init__.py b/pysr/__init__.py index 5f220035..99c6a974 100644 --- a/pysr/__init__.py +++ b/pysr/__init__.py @@ -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__ = [ diff --git a/pysr/deprecated.py b/pysr/deprecated.py index ea592272..ecfeb45e 100644 --- a/pysr/deprecated.py +++ b/pysr/deprecated.py @@ -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(): diff --git a/pysr/feynman_problems.py b/pysr/feynman_problems.py index a264a901..b64b4139 100644 --- a/pysr/feynman_problems.py +++ b/pysr/feynman_problems.py @@ -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" diff --git a/pysr/sr.py b/pysr/sr.py index 71df6cac..d824b52c 100644 --- a/pysr/sr.py +++ b/pysr/sr.py @@ -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: @@ -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"]