Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 31, 2024
1 parent 23c32d6 commit 7d6dbc1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
1 change: 0 additions & 1 deletion doc/source/api/diffpy.utils.parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ diffpy.utils.parsers.serialization module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion doc/source/api/diffpy.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ diffpy.utils.resampler module
:members:
:undoc-members:
:show-inheritance:

1 change: 0 additions & 1 deletion doc/source/api/diffpy.utils.wx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ diffpy.utils.wx.gridutils module
:members:
:undoc-members:
:show-inheritance:

9 changes: 4 additions & 5 deletions src/diffpy/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
def is_number(string):
"""
Check if the provided string can be converted to a float.
"""Check if the provided string can be converted to a float.
Parameters
----------
Expand Down Expand Up @@ -31,15 +30,15 @@ def is_number(string):
>>> is_number("NaN")
True
>>> is_number("Infinity")
True
>>> is_number("Inf")
True
"""
try:
float(string)
return True
except ValueError:
return False
return False
43 changes: 24 additions & 19 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
from diffpy.utils.validators import is_number
import pytest

@pytest.mark.parametrize("input,expected", [
("3.14", True), # Standard float
("2", True), # Integer
("-100", True), # Negative integer
("-3.14", True), # Negative float
("0", True), # Zero
("4.5e-1", True), # Scientific notation
("abc", False), # Non-numeric string
("", False), # Empty string
("3.14.15", False), # Multiple dots
("2+3", False), # Arithmetic expression
("NaN", True), # Not a Number (special float value)
("Infinity", True), # Positive infinity
("-Infinity", True), # Negative infinity
("Inf", True), # Positive infinity
("-Inf", True), # Negative infinity
])
from diffpy.utils.validators import is_number


@pytest.mark.parametrize(
"input,expected",
[
("3.14", True), # Standard float
("2", True), # Integer
("-100", True), # Negative integer
("-3.14", True), # Negative float
("0", True), # Zero
("4.5e-1", True), # Scientific notation
("abc", False), # Non-numeric string
("", False), # Empty string
("3.14.15", False), # Multiple dots
("2+3", False), # Arithmetic expression
("NaN", True), # Not a Number (special float value)
("Infinity", True), # Positive infinity
("-Infinity", True), # Negative infinity
("Inf", True), # Positive infinity
("-Inf", True), # Negative infinity
],
)
def test_is_number(input, expected):
assert is_number(input) == expected
assert is_number(input) == expected

0 comments on commit 7d6dbc1

Please sign in to comment.