Skip to content

Commit 85eb096

Browse files
committed
refactor: Remove numpy dependency from Range.to_list
- Remove numpy import and dependency from pyproject.toml - Refactor Range.to_list() to use Python's built-in range() for integers - Implement iteration-based approach for float ranges - Maintain backward compatibility with existing tests - Update version to 0.2.1 Changed files: - pyproject.toml: Removed numpy>=2.3.4 dependency, updated version - src/combinatorial_config/normalizers/range.py: Replaced np.arange() with native Python implementation
1 parent 1612f00 commit 85eb096

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
[project]
22
name = "combinatorial-config"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
description = "Add your description here"
55
authors = [
66
{ name = "devcomfort", email = "im@devcomfort.me" }
77
]
88
dependencies = [
99
"pytest>=8.4.2",
1010
"toolz>=1.1.0",
11-
"numpy>=2.3.4",
1211
]
1312
readme = "README.md"
1413
requires-python = ">= 3.8"

src/combinatorial_config/normalizers/range.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Range field normalization utilities."""
22

3-
import numpy as np
43
from ..schemas import NumberValue, RangeField, NormalizedRangeField
54
from ..validators import is_range_field
65

@@ -59,7 +58,10 @@ def to_parameters(value: RangeField) -> NormalizedRangeField:
5958
@staticmethod
6059
def to_list(value: RangeField) -> list[NumberValue]:
6160
"""
62-
Convert RangeField to a list of numeric values using numpy.arange.
61+
Convert RangeField to a list of numeric values using Python's built-in range or iteration.
62+
63+
For integer ranges, uses Python's built-in range() for efficiency.
64+
For float ranges, uses iteration to generate values.
6365
6466
Parameters
6567
----------
@@ -84,6 +86,19 @@ def to_list(value: RangeField) -> list[NumberValue]:
8486
[2, 3, 4, 5, 6, 7]
8587
>>> Range.to_list((1, 10, 2))
8688
[1, 3, 5, 7, 9]
89+
>>> Range.to_list((0.0, 1.0, 0.3))
90+
[0.0, 0.3, 0.6, 0.9]
8791
"""
8892
start, stop, step = Range.to_parameters(value)
89-
return np.arange(start, stop, step).tolist()
93+
94+
# Use built-in range for integer values (more efficient)
95+
if isinstance(start, int) and isinstance(stop, int) and isinstance(step, int):
96+
return list(range(start, stop, step))
97+
98+
# Use iteration for float values
99+
result = []
100+
current = start
101+
while current < stop:
102+
result.append(current)
103+
current += step
104+
return result

0 commit comments

Comments
 (0)