Skip to content

Commit

Permalink
Add method aliases to tiledb.VFS (#1902)
Browse files Browse the repository at this point in the history
* Add failing tests for aliases

* Add aliases to make tests pass
  • Loading branch information
sgillies authored Feb 29, 2024
1 parent e3f83a7 commit 9047c32
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Next

## Improvements

* For compatibility with fsspec and rasterio, `isdir()`, `isfile()`, and `size()` aliases have been added to the `VFS` class (#1902).

# Release 0.26.1

* TileDB-Py 0.26.1 includes TileDB Embedded [2.20.1](https://github.com/TileDB-Inc/TileDB/releases/tag/2.20.1)
Expand Down
23 changes: 23 additions & 0 deletions tiledb/tests/test_vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,26 @@ def test_open_with(self):
with self.assertRaises(IOError):
fio.write(b"foo")
self.assertEqual(fio.read(len(buffer)), buffer)


def test_vfs_isdir(tmp_path):
"""isdir is an alias for is_dir."""
fs = tiledb.VFS()
assert fs.isdir(tmp_path.as_posix())


def test_vfs_isfile(tmp_path):
"""isfile is an alias for is_file."""
tmp_file = tmp_path.joinpath("foo")
tmp_file.touch()
fs = tiledb.VFS()
assert fs.isfile(tmp_file.as_posix())


def test_vfs_size(tmp_path):
"""size is an alias for file_size."""
tmp_file = tmp_path.joinpath("foo")
buffer = b"0123456789"
tmp_file.write_bytes(buffer)
fs = tiledb.VFS()
assert fs.size(tmp_file.as_posix()) == len(buffer)
5 changes: 5 additions & 0 deletions tiledb/vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ def touch(self, uri: _AnyPath):
"""
return self._touch(_to_path_str(uri))

# Aliases for compatibility with fsspec's AbstractFileSystem.
isdir = is_dir
isfile = is_file
size = file_size


class FileIO(io.RawIOBase):
"""TileDB FileIO class that encapsulates files opened by tiledb.VFS. The file
Expand Down

0 comments on commit 9047c32

Please sign in to comment.