Spaces:
Sleeping
Sleeping
Do tests of deprecated functions
Browse files- pysr/deprecated.py +7 -2
- pysr/sr.py +2 -0
- pysr/test/test.py +13 -4
pysr/deprecated.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 1 |
"""Various functions to deprecate features."""
|
| 2 |
import warnings
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def install(*args, **kwargs):
|
| 6 |
del args, kwargs
|
| 7 |
warnings.warn(
|
| 8 |
"The `install` function has been removed. "
|
| 9 |
-
"PySR now uses the `juliacall` package to install its dependencies automatically at import time. "
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
|
|
@@ -14,8 +17,10 @@ def init_julia(*args, **kwargs):
|
|
| 14 |
del args, kwargs
|
| 15 |
warnings.warn(
|
| 16 |
"The `init_julia` function has been removed. "
|
| 17 |
-
"Julia is now initialized automatically at import time."
|
|
|
|
| 18 |
)
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def pysr(X, y, weights=None, **kwargs): # pragma: no cover
|
|
|
|
| 1 |
"""Various functions to deprecate features."""
|
| 2 |
import warnings
|
| 3 |
|
| 4 |
+
from .julia_import import jl
|
| 5 |
+
|
| 6 |
|
| 7 |
def install(*args, **kwargs):
|
| 8 |
del args, kwargs
|
| 9 |
warnings.warn(
|
| 10 |
"The `install` function has been removed. "
|
| 11 |
+
"PySR now uses the `juliacall` package to install its dependencies automatically at import time. ",
|
| 12 |
+
FutureWarning,
|
| 13 |
)
|
| 14 |
|
| 15 |
|
|
|
|
| 17 |
del args, kwargs
|
| 18 |
warnings.warn(
|
| 19 |
"The `init_julia` function has been removed. "
|
| 20 |
+
"Julia is now initialized automatically at import time.",
|
| 21 |
+
FutureWarning,
|
| 22 |
)
|
| 23 |
+
return jl
|
| 24 |
|
| 25 |
|
| 26 |
def pysr(X, y, weights=None, **kwargs): # pragma: no cover
|
pysr/sr.py
CHANGED
|
@@ -870,12 +870,14 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 870 |
warnings.warn(
|
| 871 |
"The `julia_project` parameter has been deprecated. To use a custom "
|
| 872 |
"julia project, please see `https://astroautomata.com/PySR/backend`.",
|
|
|
|
| 873 |
)
|
| 874 |
elif k == "julia_kwargs":
|
| 875 |
warnings.warn(
|
| 876 |
"The `julia_kwargs` parameter has been deprecated. To pass custom "
|
| 877 |
"keyword arguments to the julia backend, you should use environment variables. "
|
| 878 |
"See the Julia documentation for more information.",
|
|
|
|
| 879 |
)
|
| 880 |
else:
|
| 881 |
raise TypeError(
|
|
|
|
| 870 |
warnings.warn(
|
| 871 |
"The `julia_project` parameter has been deprecated. To use a custom "
|
| 872 |
"julia project, please see `https://astroautomata.com/PySR/backend`.",
|
| 873 |
+
FutureWarning,
|
| 874 |
)
|
| 875 |
elif k == "julia_kwargs":
|
| 876 |
warnings.warn(
|
| 877 |
"The `julia_kwargs` parameter has been deprecated. To pass custom "
|
| 878 |
"keyword arguments to the julia backend, you should use environment variables. "
|
| 879 |
"See the Julia documentation for more information.",
|
| 880 |
+
FutureWarning,
|
| 881 |
)
|
| 882 |
else:
|
| 883 |
raise TypeError(
|
pysr/test/test.py
CHANGED
|
@@ -11,9 +11,10 @@ import pandas as pd
|
|
| 11 |
import sympy
|
| 12 |
from sklearn.utils.estimator_checks import check_estimator
|
| 13 |
|
| 14 |
-
from .. import PySRRegressor
|
| 15 |
from ..export_latex import sympy2latex
|
| 16 |
from ..feature_selection import _handle_feature_selection, run_feature_selection
|
|
|
|
| 17 |
from ..sr import _check_assertions, _process_constraints, idx_model_selection
|
| 18 |
from ..utils import _csv_filename_to_pkl_filename
|
| 19 |
from .params import (
|
|
@@ -106,7 +107,6 @@ class TestPipeline(unittest.TestCase):
|
|
| 106 |
warm_start=True,
|
| 107 |
)
|
| 108 |
model.fit(self.X, y)
|
| 109 |
-
from pysr.sr import jl
|
| 110 |
|
| 111 |
# We should have that the model state is now a Float64 hof:
|
| 112 |
jl.test_state = model.raw_julia_state_
|
|
@@ -228,8 +228,6 @@ class TestPipeline(unittest.TestCase):
|
|
| 228 |
warm_start=True,
|
| 229 |
early_stop_condition=None,
|
| 230 |
)
|
| 231 |
-
# Check that the the julia state is saved:
|
| 232 |
-
from pysr import jl
|
| 233 |
|
| 234 |
# We should have that the model state is now a Float32 hof:
|
| 235 |
jl.test_state = regressor.raw_julia_state_
|
|
@@ -548,6 +546,17 @@ class TestMiscellaneous(unittest.TestCase):
|
|
| 548 |
# The correct value should be set:
|
| 549 |
self.assertEqual(model.fraction_replaced, 0.2)
|
| 550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
def test_power_law_warning(self):
|
| 552 |
"""Ensure that a warning is given for a power law operator."""
|
| 553 |
with self.assertWarns(UserWarning):
|
|
|
|
| 11 |
import sympy
|
| 12 |
from sklearn.utils.estimator_checks import check_estimator
|
| 13 |
|
| 14 |
+
from .. import PySRRegressor, install, jl
|
| 15 |
from ..export_latex import sympy2latex
|
| 16 |
from ..feature_selection import _handle_feature_selection, run_feature_selection
|
| 17 |
+
from ..julia_helpers import init_julia
|
| 18 |
from ..sr import _check_assertions, _process_constraints, idx_model_selection
|
| 19 |
from ..utils import _csv_filename_to_pkl_filename
|
| 20 |
from .params import (
|
|
|
|
| 107 |
warm_start=True,
|
| 108 |
)
|
| 109 |
model.fit(self.X, y)
|
|
|
|
| 110 |
|
| 111 |
# We should have that the model state is now a Float64 hof:
|
| 112 |
jl.test_state = model.raw_julia_state_
|
|
|
|
| 228 |
warm_start=True,
|
| 229 |
early_stop_condition=None,
|
| 230 |
)
|
|
|
|
|
|
|
| 231 |
|
| 232 |
# We should have that the model state is now a Float32 hof:
|
| 233 |
jl.test_state = regressor.raw_julia_state_
|
|
|
|
| 546 |
# The correct value should be set:
|
| 547 |
self.assertEqual(model.fraction_replaced, 0.2)
|
| 548 |
|
| 549 |
+
def test_deprecated_functions(self):
|
| 550 |
+
with self.assertWarns(FutureWarning):
|
| 551 |
+
install()
|
| 552 |
+
|
| 553 |
+
_jl = None
|
| 554 |
+
|
| 555 |
+
with self.assertWarns(FutureWarning):
|
| 556 |
+
_jl = init_julia()
|
| 557 |
+
|
| 558 |
+
self.assertEqual(_jl, jl)
|
| 559 |
+
|
| 560 |
def test_power_law_warning(self):
|
| 561 |
"""Ensure that a warning is given for a power law operator."""
|
| 562 |
with self.assertWarns(UserWarning):
|