Skip to content

Fix ValueError in iou calculation due to PyMuPDF Rect initialization (src/grits.py)#205

Open
KimRass wants to merge 1 commit intomicrosoft:mainfrom
KimRass:fix-grits-iou
Open

Fix ValueError in iou calculation due to PyMuPDF Rect initialization (src/grits.py)#205
KimRass wants to merge 1 commit intomicrosoft:mainfrom
KimRass:fix-grits-iou

Conversation

@KimRass
Copy link

@KimRass KimRass commented Mar 5, 2026

Description:
Currently, when computing GriTS metrics (e.g., grits_top or factored_2dmss), a ValueError is raised in the iou function in src/grits.py when using recent versions of PyMuPDF (fitz):

Traceback (most recent call last):
...
  File "/src/grits.py", line 229, in iou
    intersection = Rect(bbox1).intersect(bbox2)
...
ValueError: not enough values to unpack (expected 4, got 1)

Motivation/Root Cause:
This issue occurs because the iou function frequently receives 1D NumPy arrays for bbox1 and bbox2. While older versions of PyMuPDF might have handled this seamlessly, newer versions fail to automatically unpack 1D NumPy arrays when initializing a Rect object, interpreting the input as a single element instead of 4 coordinate values.

Changes proposed in this pull request:

  • Explicitly cast bbox1 and bbox2 to Python lists before passing them to Rect() in the iou function in src/grits.py.
  • Changed Rect(bbox1) to Rect(list(bbox1))
  • Changed .intersect(bbox2) to .intersect(list(bbox2)) (and similarly for .include_rect).

Impact:
This minor modification ensures robust compatibility with newer versions of the PyMuPDF library without altering the underlying logic or performance of the GriTS metric calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant