Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion spras/config/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
# This contains the dynamically generated algorithm schema for use in `schema.py`
__all__ = ['AlgorithmUnion']

def is_numeric(value: Any) -> bool:
"""Checks if the input value can be parsed by `float`."""
try:
float(value)
return True
except ValueError:
return False

def is_numpy_friendly(type: type[Any] | None) -> bool:
"""
Whether the passed in type can have any numpy helpers.
Expand All @@ -44,7 +52,7 @@ def python_evalish_coerce(value: Any) -> Any:
resources if wanted. This only prevents secret leakage.
"""

if not isinstance(value, str):
if not isinstance(value, str) or is_numeric(value):
return value

# These strings are in the form of function calls `function.name(param1, param2, ...)`.
Expand Down
8 changes: 8 additions & 0 deletions test/test_config.py

@ntalluri ntalluri Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to add the test cases that tony had in #488

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few of these tests (link) would only serve to test Pydantic itself, but the tests which check for specific scientific notation would be good to ensure that the weak float test does capture all of the behavior we want.

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def get_test_config():
"include": True,
"runs": {
"strings": {"dummy_mode": ["terminals", "others"], "b": 3},
# We include slightly absurd numbers here for b
# to test https://github.com/Reed-CompBio/spras/issues/484.
"scientific": {"dummy_mode": "terminals", "b": ["1e-2", "1e2"]},
# spacing in np.linspace is on purpose
"singleton_string_np_linspace": {"dummy_mode": "terminals", "b": "np.linspace(0, 5,2,)"},
"str_array_np_logspace": {"dummy_mode": ["others", "all"], "g": "np.logspace(1,1)"}
Expand Down Expand Up @@ -296,6 +299,11 @@ def test_config_values(self):
OmicsIntegrator2Params(dummy_mode=DummyMode.others, b=3)
])

value_test_util('omicsintegrator2', 'scientific', OmicsIntegrator2Params, [
OmicsIntegrator2Params(dummy_mode=DummyMode.terminals, b=100),
OmicsIntegrator2Params(dummy_mode=DummyMode.terminals, b=0.01)
])

value_test_util('omicsintegrator2', 'singleton_string_np_linspace', OmicsIntegrator2Params, [
OmicsIntegrator2Params(dummy_mode=DummyMode.terminals, b=5.0),
OmicsIntegrator2Params(dummy_mode=DummyMode.terminals, b=0.0)
Expand Down
Loading