Skip to content

Bugfix: SubFile.seek for unsignedinteger#48

Merged
pressler-vsc merged 1 commit into
mainfrom
bugfix/subfile-seek
Jun 15, 2026
Merged

Bugfix: SubFile.seek for unsignedinteger#48
pressler-vsc merged 1 commit into
mainfrom
bugfix/subfile-seek

Conversation

@pressler-vsc

Copy link
Copy Markdown
Contributor

Description

@bombaci-vsc found some unintuitive behavior with SubFile.seek when used with numpy scalar types. An example can be seen running the new test in main:

            # seeking works with  int-like
            subfile.seek(np.uint8(24), os.SEEK_SET)
>           subfile.seek(-8, os.SEEK_CUR)

test/test_core.py:790: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jbpy.core.SubFile object at 0x7f9947be7620>, offset = -8, whence = 1

    def seek(self, offset: int, whence: int = 0) -> int:
        """
        Seek to a position within the subfile.
    
        Parameters
        ----------
        offset : int
            Offset to seek
        whence : int
            0 (start), 1 (current), or 2 (end of subfile)
    
        Returns
        -------
        int
            Current offset in the SubFile
        """
        if whence == 0:
            new_pos = offset
        elif whence == 1:
>           new_pos = self._pos + offset
                      ^^^^^^^^^^^^^^^^^^
E           OverflowError: Python integer -8 out of bounds for uint8

jbpy/core.py:87: OverflowError
==================================================================================================================================================================== short test summary info =====================================================================================================================================================================
FAILED test/test_core.py::test_subfile - OverflowError: Python integer -8 out of bounds for uint8
======================================================================================================================================================================= 1 failed in 0.73s ========================================================================================================================================================================
                                                                                                                                                                                                                                                                                                                                                                  

Wrapping a few things in int seems like a reasonable remedy.

@pressler-vsc
pressler-vsc merged commit 6ddcf80 into main Jun 15, 2026
5 checks passed
@pressler-vsc
pressler-vsc deleted the bugfix/subfile-seek branch June 15, 2026 14:08
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.

2 participants