MilesCranmer commited on
Commit
0501132
1 Parent(s): 3a3b168

style: absolute import in test files for test compat

Browse files
pysr/sr.py CHANGED
@@ -120,7 +120,7 @@ def _maybe_create_inline_operators(
120
  "and underscores are allowed."
121
  )
122
  if (extra_sympy_mappings is None) or (
123
- not function_name in extra_sympy_mappings
124
  ):
125
  raise ValueError(
126
  f"Custom function {function_name} is not defined in `extra_sympy_mappings`. "
 
120
  "and underscores are allowed."
121
  )
122
  if (extra_sympy_mappings is None) or (
123
+ function_name not in extra_sympy_mappings
124
  ):
125
  raise ValueError(
126
  f"Custom function {function_name} is not defined in `extra_sympy_mappings`. "
pysr/test/params.py CHANGED
@@ -1,6 +1,6 @@
1
  import inspect
2
 
3
- from .. import PySRRegressor
4
 
5
  DEFAULT_PARAMS = inspect.signature(PySRRegressor.__init__).parameters
6
  DEFAULT_NITERATIONS = DEFAULT_PARAMS["niterations"].default
 
1
  import inspect
2
 
3
+ from pysr import PySRRegressor
4
 
5
  DEFAULT_PARAMS = inspect.signature(PySRRegressor.__init__).parameters
6
  DEFAULT_NITERATIONS = DEFAULT_PARAMS["niterations"].default
pysr/test/test.py CHANGED
@@ -11,12 +11,13 @@ import pandas as pd
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 (
21
  DEFAULT_NCYCLES,
22
  DEFAULT_NITERATIONS,
@@ -308,7 +309,10 @@ class TestPipeline(unittest.TestCase):
308
  "unused_feature": self.rstate.randn(500),
309
  }
310
  )
311
- true_fn = lambda x: np.array(x["T"] + x["x"] ** 2 + 1.323837)
 
 
 
312
  y = true_fn(X)
313
  noise = self.rstate.randn(500) * 0.01
314
  y = y + noise
@@ -373,7 +377,7 @@ class TestPipeline(unittest.TestCase):
373
  3,0.12717344,"(f0 + 1.4724599)"
374
  4,0.104823045,"pow_abs(2.2683423, cos(f3))\""""
375
  # Strip the indents:
376
- csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
377
 
378
  for from_backup in [False, True]:
379
  rand_dir = Path(tempfile.mkdtemp())
@@ -425,7 +429,7 @@ class TestPipeline(unittest.TestCase):
425
  if os.path.exists(file_to_delete):
426
  os.remove(file_to_delete)
427
 
428
- pickle_file = rand_dir / "equations.pkl"
429
  model3 = PySRRegressor.from_file(
430
  model.equation_file_, extra_sympy_mappings={"sq": lambda x: x**2}
431
  )
 
11
  import sympy
12
  from sklearn.utils.estimator_checks import check_estimator
13
 
14
+ from pysr import PySRRegressor, install, jl
15
+ from pysr.export_latex import sympy2latex
16
+ from pysr.feature_selection import _handle_feature_selection, run_feature_selection
17
+ from pysr.julia_helpers import init_julia
18
+ from pysr.sr import _check_assertions, _process_constraints, idx_model_selection
19
+ from pysr.utils import _csv_filename_to_pkl_filename
20
+
21
  from .params import (
22
  DEFAULT_NCYCLES,
23
  DEFAULT_NITERATIONS,
 
309
  "unused_feature": self.rstate.randn(500),
310
  }
311
  )
312
+
313
+ def true_fn(x):
314
+ return np.array(x["T"] + x["x"] ** 2 + 1.323837)
315
+
316
  y = true_fn(X)
317
  noise = self.rstate.randn(500) * 0.01
318
  y = y + noise
 
377
  3,0.12717344,"(f0 + 1.4724599)"
378
  4,0.104823045,"pow_abs(2.2683423, cos(f3))\""""
379
  # Strip the indents:
380
+ csv_file_data = "\n".join([line.strip() for line in csv_file_data.split("\n")])
381
 
382
  for from_backup in [False, True]:
383
  rand_dir = Path(tempfile.mkdtemp())
 
429
  if os.path.exists(file_to_delete):
430
  os.remove(file_to_delete)
431
 
432
+ # pickle_file = rand_dir / "equations.pkl"
433
  model3 = PySRRegressor.from_file(
434
  model.equation_file_, extra_sympy_mappings={"sq": lambda x: x**2}
435
  )
pysr/test/test_jax.py CHANGED
@@ -5,7 +5,7 @@ import numpy as np
5
  import pandas as pd
6
  import sympy
7
 
8
- from .. import PySRRegressor, sympy2jax
9
 
10
 
11
  class TestJAX(unittest.TestCase):
@@ -89,7 +89,10 @@ class TestJAX(unittest.TestCase):
89
  def test_feature_selection_custom_operators(self):
90
  rstate = np.random.RandomState(0)
91
  X = pd.DataFrame({f"k{i}": rstate.randn(2000) for i in range(10, 21)})
92
- cos_approx = lambda x: 1 - (x**2) / 2 + (x**4) / 24 + (x**6) / 720
 
 
 
93
  y = X["k15"] ** 2 + 2 * cos_approx(X["k20"])
94
 
95
  model = PySRRegressor(
 
5
  import pandas as pd
6
  import sympy
7
 
8
+ from pysr import PySRRegressor, sympy2jax
9
 
10
 
11
  class TestJAX(unittest.TestCase):
 
89
  def test_feature_selection_custom_operators(self):
90
  rstate = np.random.RandomState(0)
91
  X = pd.DataFrame({f"k{i}": rstate.randn(2000) for i in range(10, 21)})
92
+
93
+ def cos_approx(x):
94
+ return 1 - (x**2) / 2 + (x**4) / 24 + (x**6) / 720
95
+
96
  y = X["k15"] ** 2 + 2 * cos_approx(X["k20"])
97
 
98
  model = PySRRegressor(
pysr/test/test_startup.py CHANGED
@@ -9,8 +9,9 @@ from pathlib import Path
9
 
10
  import numpy as np
11
 
12
- from .. import PySRRegressor
13
- from ..julia_import import jl_version
 
14
  from .params import DEFAULT_NITERATIONS, DEFAULT_POPULATIONS
15
 
16
 
 
9
 
10
  import numpy as np
11
 
12
+ from pysr import PySRRegressor
13
+ from pysr.julia_import import jl_version
14
+
15
  from .params import DEFAULT_NITERATIONS, DEFAULT_POPULATIONS
16
 
17
 
pysr/test/test_torch.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import pandas as pd
5
  import sympy
6
 
7
- from .. import PySRRegressor, sympy2torch
8
 
9
 
10
  class TestTorch(unittest.TestCase):
 
4
  import pandas as pd
5
  import sympy
6
 
7
+ from pysr import PySRRegressor, sympy2torch
8
 
9
 
10
  class TestTorch(unittest.TestCase):