MilesCranmer commited on
Commit
0b9e421
1 Parent(s): b896bd3

Move all deprecated functions to deprecated.py

Browse files
Files changed (4) hide show
  1. pysr/__init__.py +2 -1
  2. pysr/deprecated.py +54 -0
  3. pysr/feynman_problems.py +1 -1
  4. pysr/sr.py +0 -42
pysr/__init__.py CHANGED
@@ -1,9 +1,10 @@
1
  from . import sklearn_monkeypatch
 
2
  from .export_jax import sympy2jax
3
  from .export_torch import sympy2torch
4
  from .feynman_problems import FeynmanProblem, Problem
5
  from .julia_helpers import install
6
- from .sr import PySRRegressor, best, best_callable, best_row, best_tex, pysr
7
  from .version import __version__
8
 
9
  __all__ = [
 
1
  from . import sklearn_monkeypatch
2
+ from .deprecated import best, best_callable, best_row, best_tex, pysr
3
  from .export_jax import sympy2jax
4
  from .export_torch import sympy2torch
5
  from .feynman_problems import FeynmanProblem, Problem
6
  from .julia_helpers import install
7
+ from .sr import PySRRegressor
8
  from .version import __version__
9
 
10
  __all__ = [
pysr/deprecated.py CHANGED
@@ -1,4 +1,58 @@
1
  """Various functions to deprecate features."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
 
4
  def make_deprecated_kwargs_for_pysr_regressor():
 
1
  """Various functions to deprecate features."""
2
+ import warnings
3
+
4
+
5
+ def pysr(X, y, weights=None, **kwargs): # pragma: no cover
6
+ from .sr import PySRRegressor
7
+
8
+ warnings.warn(
9
+ "Calling `pysr` is deprecated. "
10
+ "Please use `model = PySRRegressor(**params); "
11
+ "model.fit(X, y)` going forward.",
12
+ FutureWarning,
13
+ )
14
+ model = PySRRegressor(**kwargs)
15
+ model.fit(X, y, weights=weights)
16
+ return model.equations_
17
+
18
+
19
+ def best(*args, **kwargs): # pragma: no cover
20
+ raise NotImplementedError(
21
+ "`best` has been deprecated. "
22
+ "Please use the `PySRRegressor` interface. "
23
+ "After fitting, you can return `.sympy()` "
24
+ "to get the sympy representation "
25
+ "of the best equation."
26
+ )
27
+
28
+
29
+ def best_row(*args, **kwargs): # pragma: no cover
30
+ raise NotImplementedError(
31
+ "`best_row` has been deprecated. "
32
+ "Please use the `PySRRegressor` interface. "
33
+ "After fitting, you can run `print(model)` to view the best equation, "
34
+ "or "
35
+ "`model.get_best()` to return the best equation's "
36
+ "row in `model.equations_`."
37
+ )
38
+
39
+
40
+ def best_tex(*args, **kwargs): # pragma: no cover
41
+ raise NotImplementedError(
42
+ "`best_tex` has been deprecated. "
43
+ "Please use the `PySRRegressor` interface. "
44
+ "After fitting, you can return `.latex()` to "
45
+ "get the sympy representation "
46
+ "of the best equation."
47
+ )
48
+
49
+
50
+ def best_callable(*args, **kwargs): # pragma: no cover
51
+ raise NotImplementedError(
52
+ "`best_callable` has been deprecated. Please use the `PySRRegressor` "
53
+ "interface. After fitting, you can use "
54
+ "`.predict(X)` to use the best callable."
55
+ )
56
 
57
 
58
  def make_deprecated_kwargs_for_pysr_regressor():
pysr/feynman_problems.py CHANGED
@@ -4,7 +4,7 @@ from pathlib import Path
4
 
5
  import numpy as np
6
 
7
- from .sr import best, pysr
8
 
9
  PKG_DIR = Path(__file__).parents[1]
10
  FEYNMAN_DATASET = PKG_DIR / "datasets" / "FeynmanEquations.csv"
 
4
 
5
  import numpy as np
6
 
7
+ from .deprecated import best, pysr
8
 
9
  PKG_DIR = Path(__file__).parents[1]
10
  FEYNMAN_DATASET = PKG_DIR / "datasets" / "FeynmanEquations.csv"
pysr/sr.py CHANGED
@@ -48,17 +48,6 @@ Main = None # TODO: Rename to more descriptive name like "julia_runtime"
48
  already_ran = False
49
 
50
 
51
- def pysr(X, y, weights=None, **kwargs): # pragma: no cover
52
- warnings.warn(
53
- "Calling `pysr` is deprecated. "
54
- "Please use `model = PySRRegressor(**params); model.fit(X, y)` going forward.",
55
- FutureWarning,
56
- )
57
- model = PySRRegressor(**kwargs)
58
- model.fit(X, y, weights=weights)
59
- return model.equations_
60
-
61
-
62
  def _process_constraints(binary_operators, unary_operators, constraints):
63
  constraints = constraints.copy()
64
  for op in unary_operators:
@@ -181,37 +170,6 @@ def _check_assertions(
181
  )
182
 
183
 
184
- def best(*args, **kwargs): # pragma: no cover
185
- raise NotImplementedError(
186
- "`best` has been deprecated. Please use the `PySRRegressor` interface. "
187
- "After fitting, you can return `.sympy()` to get the sympy representation "
188
- "of the best equation."
189
- )
190
-
191
-
192
- def best_row(*args, **kwargs): # pragma: no cover
193
- raise NotImplementedError(
194
- "`best_row` has been deprecated. Please use the `PySRRegressor` interface. "
195
- "After fitting, you can run `print(model)` to view the best equation, or "
196
- "`model.get_best()` to return the best equation's row in `model.equations_`."
197
- )
198
-
199
-
200
- def best_tex(*args, **kwargs): # pragma: no cover
201
- raise NotImplementedError(
202
- "`best_tex` has been deprecated. Please use the `PySRRegressor` interface. "
203
- "After fitting, you can return `.latex()` to get the sympy representation "
204
- "of the best equation."
205
- )
206
-
207
-
208
- def best_callable(*args, **kwargs): # pragma: no cover
209
- raise NotImplementedError(
210
- "`best_callable` has been deprecated. Please use the `PySRRegressor` "
211
- "interface. After fitting, you can use `.predict(X)` to use the best callable."
212
- )
213
-
214
-
215
  # Class validation constants
216
  VALID_OPTIMIZER_ALGORITHMS = ["NelderMead", "BFGS"]
217
 
 
48
  already_ran = False
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
51
  def _process_constraints(binary_operators, unary_operators, constraints):
52
  constraints = constraints.copy()
53
  for op in unary_operators:
 
170
  )
171
 
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  # Class validation constants
174
  VALID_OPTIMIZER_ALGORITHMS = ["NelderMead", "BFGS"]
175