Skip to content

Commit a6d3995

Browse files
committed
feat: Improved typing, exception if neither step nor decimals is set
1 parent d0d40f4 commit a6d3995

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

freqtrade/optimize/space/decimalspace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(
88
high: float,
99
*,
1010
step: float | None = None,
11-
decimals: int = 3,
11+
decimals: int | None = None,
1212
name=None,
1313
):
1414
"""
@@ -22,6 +22,8 @@ def __init__(
2222
"""
2323
if decimals is not None and step is not None:
2424
raise ValueError("You can only set one of decimals or step")
25+
if decimals is None and step is None:
26+
raise ValueError("You must set one of decimals or step")
2527
# Convert decimals to step
2628
self.step = step or 1 / 10**decimals
2729
self.name = name

tests/optimize/test_hyperopt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,9 @@ def test_SKDecimal():
11971197
with pytest.raises(ValueError):
11981198
SKDecimal(1, 2, step=5, decimals=0.2)
11991199

1200+
with pytest.raises(ValueError):
1201+
SKDecimal(1, 2, step=None, decimals=None)
1202+
12001203
s = SKDecimal(1, 2, step=0.1, decimals=None)
12011204
assert s.step == 0.1
12021205
assert s._contains(1.1)

0 commit comments

Comments
 (0)