Skip to content

Commit c5c7a8a

Browse files
committed
Fix Decimal handling in FrameSet broken by changes in #141
In particular the values of curr_stride, curr_min_stride, curr_max_stride may be None during FrameSet._framesToFrameRangesDecimal if a new frange part has just been started. This was previously protected against by the check `isinstance(curr_stride, decimal.Decimal)` which was False for None values. Add more test cases to prevent regression in Decimal range handling Use int() unconditionally on exponent to be consistent across codebase Use _build alias in _framesToFrameRangesDecimal to be consistent with _framesToFrameRangesFloat
1 parent 4ae10cd commit c5c7a8a

File tree

13 files changed

+27
-19
lines changed

13 files changed

+27
-19
lines changed

src/fileseq/frameset.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,8 @@ def _build_frange_part(start: object, stop: object, stride: FrameValue | None, z
12031203
Private method: builds a proper and padded frame range string.
12041204
12051205
Args:
1206-
start (int): first frame
1207-
stop (int or None): last frame
1206+
start (int or decimal.Decimal): first frame
1207+
stop (int or or decimal.Decimal or None): last frame
12081208
stride (int or None): increment
12091209
zfill (int): width for zero padding
12101210
@@ -1347,6 +1347,7 @@ def _framesToFrameRangesDecimal(
13471347
Yields:
13481348
str:
13491349
"""
1350+
_build = FrameSet._build_frange_part
13501351
_build_decimal = FrameSet._build_frange_part_decimal
13511352

13521353
curr_start: decimal.Decimal | None = None
@@ -1374,10 +1375,8 @@ def _framesToFrameRangesDecimal(
13741375
# Check whether stride difference could be caused by rounding
13751376
if len(curr_strides) == 1:
13761377
stride_delta = abs(curr_stride - new_stride)
1377-
exponent = stride_delta.as_tuple().exponent
1378-
# Handle case where exponent might be a string literal
1379-
exp_value = int(exponent) if isinstance(exponent, str) else exponent
1380-
max_stride_delta = decimal.Decimal(1).scaleb(exp_value)
1378+
exponent = int(stride_delta.as_tuple().exponent)
1379+
max_stride_delta = decimal.Decimal(1).scaleb(exponent)
13811380
if stride_delta <= max_stride_delta:
13821381
curr_strides.add(new_stride)
13831382

@@ -1423,18 +1422,22 @@ def _framesToFrameRangesDecimal(
14231422
if curr_stride == new_stride:
14241423
curr_count += 1
14251424
elif curr_count == 2 and curr_stride != 1:
1426-
yield FrameSet._build_frange_part(curr_start, curr_start, None, zfill)
1425+
yield _build(curr_start, curr_start, None, zfill)
14271426
curr_start = last_frame
14281427
curr_stride = new_stride
14291428
curr_strides = {new_stride}
14301429
curr_min_stride = None
14311430
curr_max_stride = None
14321431
else:
14331432
stride = curr_strides.pop() if len(curr_strides) == 1 else None
1434-
assert curr_min_stride is not None
1435-
assert curr_max_stride is not None
1436-
yield _build_decimal(curr_start, last_frame, curr_count,
1437-
stride, curr_min_stride, curr_max_stride, zfill)
1433+
assert curr_start is not None
1434+
if curr_stride is None:
1435+
yield _build(curr_start, curr_frame, curr_stride, zfill)
1436+
else:
1437+
assert curr_min_stride is not None
1438+
assert curr_max_stride is not None
1439+
yield _build_decimal(curr_start, last_frame, curr_count,
1440+
stride, curr_min_stride, curr_max_stride, zfill)
14381441
curr_stride = None
14391442
curr_strides = set()
14401443
curr_min_stride = None
@@ -1445,15 +1448,18 @@ def _framesToFrameRangesDecimal(
14451448
last_frame = curr_frame
14461449

14471450
if curr_count == 2 and curr_stride != 1:
1448-
yield FrameSet._build_frange_part(curr_start, curr_start, None, zfill)
1449-
yield FrameSet._build_frange_part(curr_frame, curr_frame, None, zfill)
1451+
yield _build(curr_start, curr_start, None, zfill)
1452+
yield _build(curr_frame, curr_frame, None, zfill)
14501453
else:
14511454
stride = curr_strides.pop() if len(curr_strides) == 1 else None
14521455
assert curr_start is not None
1453-
assert curr_min_stride is not None
1454-
assert curr_max_stride is not None
1455-
yield _build_decimal(curr_start, curr_frame, curr_count,
1456-
stride, curr_min_stride, curr_max_stride, zfill)
1456+
if curr_stride is None:
1457+
yield _build(curr_start, curr_frame, curr_stride, zfill)
1458+
else:
1459+
assert curr_min_stride is not None
1460+
assert curr_max_stride is not None
1461+
yield _build_decimal(curr_start, curr_frame, curr_count,
1462+
stride, curr_min_stride, curr_max_stride, zfill)
14571463

14581464
@staticmethod
14591465
def framesToFrameRanges(

test/subframe_seq/quux.02.3333.exr

Whitespace-only changes.

test/subframe_seq/quux.02.6667.exr

Whitespace-only changes.

test/subframe_seq/quux.03.0000.exr

Whitespace-only changes.

test/subframe_seq/quux.03.3333.exr

Whitespace-only changes.

test/subframe_seq/qux.00.0000.exr

Whitespace-only changes.

test/subframe_seq/qux.00.3333.exr

Whitespace-only changes.

test/subframe_seq/qux.00.6667.exr

Whitespace-only changes.

test/subframe_seq/qux.01.0000.exr

Whitespace-only changes.

test/subframe_seq/qux.01.3333.exr

Whitespace-only changes.

0 commit comments

Comments
 (0)