Skip to content

Commit

Permalink
Fix read, seek with numpy integer sizes (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihnorton committed Mar 18, 2024
1 parent 4d56373 commit a80f297
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tiledb/tests/test_vfs.py
Expand Up @@ -142,6 +142,11 @@ def test_write_read(self):

fio = vfs.open(self.path("foo").encode("utf-8"), "rb")
self.assertEqual(fio.read(3), buffer)
# test read with numpy integers
fio.seek(np.int64(0))
self.assertEqual(fio.read(np.int32(3)), buffer)
fio.seek(np.int64(0))
self.assertEqual(fio.read(np.uint64(3)), buffer)
fio.close()

# write / read empty input
Expand Down
4 changes: 2 additions & 2 deletions tiledb/vfs.py
Expand Up @@ -418,7 +418,7 @@ def seek(self, offset: int, whence: int = 0):
beginning of the file, 1 uses the current file position, and 2 uses the
end of the file as the reference point. whence can be omitted and defaults to 0.
"""
if not isinstance(offset, int):
if not np.issubdtype(type(offset), np.integer):
raise TypeError(
f"Offset must be an integer or None (got type {type(offset)})"
)
Expand Down Expand Up @@ -459,7 +459,7 @@ def read(self, size: int = -1) -> bytes:
:return: The bytes in the file
"""
if not isinstance(size, int):
if not np.issubdtype(type(size), np.integer):
raise TypeError(f"size must be an integer or None (got type {type(size)})")
if not self.readable():
raise IOError("Cannot read from write-only FileIO handle")
Expand Down

0 comments on commit a80f297

Please sign in to comment.