Skip to content

Commit 9047c32

Browse files
authored
Add method aliases to tiledb.VFS (#1902)
* Add failing tests for aliases * Add aliases to make tests pass
1 parent e3f83a7 commit 9047c32

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Next
2+
3+
## Improvements
4+
5+
* For compatibility with fsspec and rasterio, `isdir()`, `isfile()`, and `size()` aliases have been added to the `VFS` class (#1902).
6+
17
# Release 0.26.1
28

39
* TileDB-Py 0.26.1 includes TileDB Embedded [2.20.1](https://github.com/TileDB-Inc/TileDB/releases/tag/2.20.1)

tiledb/tests/test_vfs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,26 @@ def test_open_with(self):
287287
with self.assertRaises(IOError):
288288
fio.write(b"foo")
289289
self.assertEqual(fio.read(len(buffer)), buffer)
290+
291+
292+
def test_vfs_isdir(tmp_path):
293+
"""isdir is an alias for is_dir."""
294+
fs = tiledb.VFS()
295+
assert fs.isdir(tmp_path.as_posix())
296+
297+
298+
def test_vfs_isfile(tmp_path):
299+
"""isfile is an alias for is_file."""
300+
tmp_file = tmp_path.joinpath("foo")
301+
tmp_file.touch()
302+
fs = tiledb.VFS()
303+
assert fs.isfile(tmp_file.as_posix())
304+
305+
306+
def test_vfs_size(tmp_path):
307+
"""size is an alias for file_size."""
308+
tmp_file = tmp_path.joinpath("foo")
309+
buffer = b"0123456789"
310+
tmp_file.write_bytes(buffer)
311+
fs = tiledb.VFS()
312+
assert fs.size(tmp_file.as_posix()) == len(buffer)

tiledb/vfs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ def touch(self, uri: _AnyPath):
304304
"""
305305
return self._touch(_to_path_str(uri))
306306

307+
# Aliases for compatibility with fsspec's AbstractFileSystem.
308+
isdir = is_dir
309+
isfile = is_file
310+
size = file_size
311+
307312

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

0 commit comments

Comments
 (0)