Skip to content

Commit

Permalink
fix: only require sympy mapping if supports_sympy
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Dec 14, 2024
1 parent 7334704 commit ddea9a3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pysr/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def _maybe_create_inline_operators(
binary_operators: list[str],
unary_operators: list[str],
extra_sympy_mappings: dict[str, Callable] | None,
expression_spec: AbstractExpressionSpec,
) -> tuple[list[str], list[str]]:
binary_operators = binary_operators.copy()
unary_operators = unary_operators.copy()
Expand All @@ -132,9 +133,11 @@ def _maybe_create_inline_operators(
"Only alphanumeric characters, numbers, "
"and underscores are allowed."
)
if (extra_sympy_mappings is None) or (
function_name not in extra_sympy_mappings
):
missing_sympy_mapping = (
extra_sympy_mappings is None
or function_name not in extra_sympy_mappings
)
if missing_sympy_mapping and expression_spec.supports_sympy:
raise ValueError(
f"Custom function {function_name} is not defined in `extra_sympy_mappings`. "
"You can define it with, "
Expand Down Expand Up @@ -1846,6 +1849,7 @@ def _run(
binary_operators=binary_operators,
unary_operators=unary_operators,
extra_sympy_mappings=self.extra_sympy_mappings,
expression_spec=self.expression_spec_,
)
if constraints is not None:
_constraints = _process_constraints(
Expand Down

0 comments on commit ddea9a3

Please sign in to comment.