Skip to content

Commit

Permalink
style: absolute import in test files for test compat
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jun 16, 2024
1 parent 3a3b168 commit 0501132
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pysr/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _maybe_create_inline_operators(
"and underscores are allowed."
)
if (extra_sympy_mappings is None) or (
not function_name in extra_sympy_mappings
function_name not in extra_sympy_mappings
):
raise ValueError(
f"Custom function {function_name} is not defined in `extra_sympy_mappings`. "
Expand Down
2 changes: 1 addition & 1 deletion pysr/test/params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect

from .. import PySRRegressor
from pysr import PySRRegressor

DEFAULT_PARAMS = inspect.signature(PySRRegressor.__init__).parameters
DEFAULT_NITERATIONS = DEFAULT_PARAMS["niterations"].default
Expand Down
22 changes: 13 additions & 9 deletions pysr/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import sympy
from sklearn.utils.estimator_checks import check_estimator

from .. import PySRRegressor, install, jl
from ..export_latex import sympy2latex
from ..feature_selection import _handle_feature_selection, run_feature_selection
from ..julia_helpers import init_julia
from ..sr import _check_assertions, _process_constraints, idx_model_selection
from ..utils import _csv_filename_to_pkl_filename
from pysr import PySRRegressor, install, jl
from pysr.export_latex import sympy2latex
from pysr.feature_selection import _handle_feature_selection, run_feature_selection
from pysr.julia_helpers import init_julia
from pysr.sr import _check_assertions, _process_constraints, idx_model_selection
from pysr.utils import _csv_filename_to_pkl_filename

from .params import (
DEFAULT_NCYCLES,
DEFAULT_NITERATIONS,
Expand Down Expand Up @@ -308,7 +309,10 @@ def test_pandas_resample_with_nested_constraints(self):
"unused_feature": self.rstate.randn(500),
}
)
true_fn = lambda x: np.array(x["T"] + x["x"] ** 2 + 1.323837)

def true_fn(x):
return np.array(x["T"] + x["x"] ** 2 + 1.323837)

y = true_fn(X)
noise = self.rstate.randn(500) * 0.01
y = y + noise
Expand Down Expand Up @@ -373,7 +377,7 @@ def test_load_model(self):
3,0.12717344,"(f0 + 1.4724599)"
4,0.104823045,"pow_abs(2.2683423, cos(f3))\""""
# Strip the indents:
csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
csv_file_data = "\n".join([line.strip() for line in csv_file_data.split("\n")])

for from_backup in [False, True]:
rand_dir = Path(tempfile.mkdtemp())
Expand Down Expand Up @@ -425,7 +429,7 @@ def test_load_model_simple(self):
if os.path.exists(file_to_delete):
os.remove(file_to_delete)

pickle_file = rand_dir / "equations.pkl"
# pickle_file = rand_dir / "equations.pkl"
model3 = PySRRegressor.from_file(
model.equation_file_, extra_sympy_mappings={"sq": lambda x: x**2}
)
Expand Down
7 changes: 5 additions & 2 deletions pysr/test/test_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
import sympy

from .. import PySRRegressor, sympy2jax
from pysr import PySRRegressor, sympy2jax


class TestJAX(unittest.TestCase):
Expand Down Expand Up @@ -89,7 +89,10 @@ def test_pipeline(self):
def test_feature_selection_custom_operators(self):
rstate = np.random.RandomState(0)
X = pd.DataFrame({f"k{i}": rstate.randn(2000) for i in range(10, 21)})
cos_approx = lambda x: 1 - (x**2) / 2 + (x**4) / 24 + (x**6) / 720

def cos_approx(x):
return 1 - (x**2) / 2 + (x**4) / 24 + (x**6) / 720

y = X["k15"] ** 2 + 2 * cos_approx(X["k20"])

model = PySRRegressor(
Expand Down
5 changes: 3 additions & 2 deletions pysr/test/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import numpy as np

from .. import PySRRegressor
from ..julia_import import jl_version
from pysr import PySRRegressor
from pysr.julia_import import jl_version

from .params import DEFAULT_NITERATIONS, DEFAULT_POPULATIONS


Expand Down
2 changes: 1 addition & 1 deletion pysr/test/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import sympy

from .. import PySRRegressor, sympy2torch
from pysr import PySRRegressor, sympy2torch


class TestTorch(unittest.TestCase):
Expand Down

0 comments on commit 0501132

Please sign in to comment.