File tree 2 files changed +5
-6
lines changed
2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -44,12 +44,8 @@ class TimeUnit(StringEnum):
44
44
DURATION = 'dur'
45
45
46
46
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')$' ,
53
49
flags = re .IGNORECASE )
54
50
55
51
TValue = TypeVar ('TValue' , int , float )
Original file line number Diff line number Diff line change 12
12
['1ep' , 1 , TimeUnit .EPOCH ],
13
13
['2ba' , 2 , TimeUnit .BATCH ],
14
14
['3e10sp' , 3 * 10 ** 10 , TimeUnit .SAMPLE ],
15
+ ['3_0e10sp' , 30 * 10 ** 10 , TimeUnit .SAMPLE ],
15
16
['4tok' , 4 , TimeUnit .TOKEN ],
17
+ ['4_000tok' , 4000 , TimeUnit .TOKEN ],
18
+ ['4_00_0tok' , 4000 , TimeUnit .TOKEN ],
16
19
['0.5dur' , 0.5 , TimeUnit .DURATION ],
17
20
])
18
21
def test_time_parse (time_string : str , expected_value : int , expected_unit : TimeUnit ):
You can’t perform that action at this time.
0 commit comments