Skip to content

Commit 3c7b46f

Browse files
authored
Merge pull request #884 from MilesCranmer/compat-3.8
Compat with older Python
2 parents 0465b49 + ab0afe9 commit 3c7b46f

15 files changed

+44
-11
lines changed

.github/workflows/CI.yml

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
python-version: '3.12'
4242
os: ubuntu-latest
4343
test-id: include
44+
- julia-version: '1'
45+
python-version: '3.8'
46+
os: ubuntu-latest
47+
test-id: include
4448

4549
steps:
4650
- uses: actions/checkout@v4

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
description = "Simple and efficient symbolic regression"
1212
readme = {file = "README.md", content-type = "text/markdown"}
1313
license = {file = "LICENSE"}
14-
requires-python = ">=3.10"
14+
requires-python = ">=3.8"
1515
classifiers = [
1616
"Programming Language :: Python :: 3",
1717
"Operating System :: OS Independent",
@@ -39,7 +39,7 @@ dev = [
3939
"mypy>=1,<2",
4040
"nbval>=0.11,<0.12",
4141
"pandas-stubs",
42-
"pre-commit>=3.7,<5",
42+
"pre-commit>=3.0,<5",
4343
"pytest-cov>=5,<7",
4444
"pytest>=8,<9",
4545
"tensorboard>=2,<3",

pysr/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
35

pysr/denoising.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Functions for denoising data during preprocessing."""
22

3+
from __future__ import annotations
4+
35
from typing import cast
46

57
import numpy as np

pysr/export.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import copy
24
from collections.abc import Callable
35

pysr/export_latex.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Functions to help export PySR equations to LaTeX."""
22

3+
from __future__ import annotations
4+
35
import pandas as pd
46
import sympy # type: ignore
57
from sympy.printing.latex import LatexPrinter # type: ignore

pysr/export_numpy.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Code for exporting discovered expressions to numpy"""
22

3+
from __future__ import annotations
4+
35
import warnings
46

57
import numpy as np

pysr/export_sympy.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Define utilities to export to sympy"""
22

3+
from __future__ import annotations
4+
35
from collections.abc import Callable
46

57
import sympy # type: ignore

pysr/expression_specs.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from __future__ import annotations
2+
13
import copy
24
from abc import ABC, abstractmethod
35
from textwrap import dedent
4-
from typing import TYPE_CHECKING, Any, NewType, TypeAlias, overload
6+
from typing import TYPE_CHECKING, Any, NewType, overload
57

68
import numpy as np
79
import pandas as pd
@@ -10,6 +12,11 @@
1012
from .julia_helpers import jl_array
1113
from .julia_import import AnyValue, SymbolicRegression, jl
1214

15+
try:
16+
from typing import TypeAlias
17+
except ImportError:
18+
from typing_extensions import TypeAlias
19+
1320
# For type checking purposes
1421
if TYPE_CHECKING:
1522
from .sr import PySRRegressor # pragma: no cover

pysr/feature_selection.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Functions for doing feature selection during preprocessing."""
22

3+
from __future__ import annotations
4+
35
import logging
46
from typing import cast
57

pysr/julia_extensions.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""This file installs and loads extensions for SymbolicRegression."""
22

3+
from __future__ import annotations
4+
35
from typing import Literal
46

57
from .julia_import import Pkg, jl

pysr/julia_registry_helpers.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Utilities for managing Julia registry preferences during package operations."""
22

3+
from __future__ import annotations
4+
35
import os
46
import warnings
57
from collections.abc import Callable

pysr/logger_specs.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24
from dataclasses import dataclass
35
from typing import Any

pysr/sr.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Define the PySRRegressor scikit-learn interface."""
22

3+
from __future__ import annotations
4+
35
import copy
46
import logging
57
import os
@@ -13,7 +15,7 @@
1315
from io import StringIO
1416
from multiprocessing import cpu_count
1517
from pathlib import Path
16-
from typing import Any, Literal, cast
18+
from typing import Any, List, Literal, Tuple, Union, cast
1719

1820
import numpy as np
1921
import pandas as pd
@@ -94,7 +96,7 @@ def _process_constraints(
9496
)
9597
constraints[op] = (-1, -1)
9698

97-
constraint_tuple = cast(tuple[int, int], constraints[op])
99+
constraint_tuple = cast(Tuple[int, int], constraints[op])
98100
if op in ["plus", "sub", "+", "-"]:
99101
if constraint_tuple[0] != constraint_tuple[1]:
100102
raise NotImplementedError(
@@ -1313,7 +1315,7 @@ def julia_options_(self):
13131315
def julia_state_(self):
13141316
"""The deserialized state."""
13151317
return cast(
1316-
tuple[VectorValue, AnyValue] | None,
1318+
Union[Tuple[VectorValue, AnyValue], None],
13171319
jl_deserialize(self.julia_state_stream_),
13181320
)
13191321

@@ -1640,7 +1642,7 @@ def _validate_data_X_y(self, X: Any, y: Any) -> tuple[ndarray, ndarray]:
16401642
raw_out = self._validate_data(X=X, y=y, reset=True, multi_output=True) # type: ignore
16411643
else:
16421644
raw_out = validate_data(self, X=X, y=y, reset=True, multi_output=True) # type: ignore
1643-
return cast(tuple[ndarray, ndarray], raw_out)
1645+
return cast(Tuple[ndarray, ndarray], raw_out)
16441646

16451647
def _validate_data_X(self, X: Any) -> ndarray:
16461648
if OLD_SKLEARN:
@@ -2629,7 +2631,7 @@ def get_hof(self, search_output=None) -> pd.DataFrame | list[pd.DataFrame]:
26292631

26302632
_validate_export_mappings(self.extra_jax_mappings, self.extra_torch_mappings)
26312633

2632-
equation_file_contents = cast(list[pd.DataFrame], self.equation_file_contents_)
2634+
equation_file_contents = cast(List[pd.DataFrame], self.equation_file_contents_)
26332635

26342636
ret_outputs = [
26352637
pd.concat(

pysr/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import inspect
55
import re
66
from pathlib import Path
7-
from typing import Any, TypeVar
7+
from typing import Any, List, TypeVar, Union
88

99
from numpy import ndarray
1010
from sklearn.utils.validation import _check_feature_names_in # type: ignore
1111

1212
T = TypeVar("T", bound=Any)
1313

14-
ArrayLike = ndarray | list[T]
15-
PathLike = str | Path
14+
ArrayLike = Union[ndarray, List[T]]
15+
PathLike = Union[str, Path]
1616

1717

1818
_regexp_im = re.compile(r"\b(\d+\.\d+)im\b")

0 commit comments

Comments
 (0)