Skip to content

Commit ff59e86

Browse files
megha95mvpatel2000
andauthored
regex changed in time.py (#2378)
* regex changed in time.py * comment change * Update composer/core/time.py Co-authored-by: Mihir Patel <[email protected]> --------- Co-authored-by: Mihir Patel <[email protected]>
1 parent 8fb5a1a commit ff59e86

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

composer/core/time.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ class TimeUnit(StringEnum):
4444
DURATION = 'dur'
4545

4646

47-
# regex for parsing integers / decimals / scientific notation
48-
_NUM_REGEX = r'-?[\d.]+(?:e-?\d+)?'
49-
50-
# regex for parsing a time string.
51-
_TIME_STR_REGEX = re.compile(r'^(?:' + r'|'.join(fr'(?:({_NUM_REGEX})({time_unit.value}))' for time_unit in TimeUnit) +
52-
r')$',
47+
# regex for parsing time string, matches timeunit and chars prior to unit as value
48+
_TIME_STR_REGEX = re.compile(r'^(.+)(' + r'|'.join([fr'{time_unit.value}' for time_unit in TimeUnit]) + r')$',
5349
flags=re.IGNORECASE)
5450

5551
TValue = TypeVar('TValue', int, float)

tests/test_time.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
['1ep', 1, TimeUnit.EPOCH],
1313
['2ba', 2, TimeUnit.BATCH],
1414
['3e10sp', 3 * 10**10, TimeUnit.SAMPLE],
15+
['3_0e10sp', 30 * 10**10, TimeUnit.SAMPLE],
1516
['4tok', 4, TimeUnit.TOKEN],
17+
['4_000tok', 4000, TimeUnit.TOKEN],
18+
['4_00_0tok', 4000, TimeUnit.TOKEN],
1619
['0.5dur', 0.5, TimeUnit.DURATION],
1720
])
1821
def test_time_parse(time_string: str, expected_value: int, expected_unit: TimeUnit):

0 commit comments

Comments
 (0)