Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read, seek with numpy integer sizes #1927

Merged
merged 1 commit into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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