TileDB-Py
TileDB-Py copied to clipboard
Feature: Support `pathlib.Path`
Summary
When reading/writing arrays, tiledb
does not support pathlib.Path
for file URIs.
Details
When using a pathlib.Path
to open a new array, the first write triggers an array creation event that fails with the following error (truncated):
File "tiledb/libtiledb.pyx", line 962, in tiledb.libtiledb.Array.create
File "tiledb/libtiledb.pyx", line 527, in tiledb.libtiledb.unicode_path
File "tiledb/libtiledb.pyx", line 520, in tiledb.libtiledb.ustring
TypeError: ustring() must be a string or a bytes-like object, not <class 'pathlib.PosixPath'>
What I Expect to Happen
When opening a tiledb.Array
, I should be able to use a pathlib.Path
object. Additionally, using the os
pathing objects should also be possible.
Implementation
The stack trace seems to indicate the code is written in Cython. This should be a relatively easy feature to implement with two lines of code to type check if the input object is pathlib.Path
, then casting with str(pathlib.Path("path/to/file.tiledb"))
.
If you're open to taking PRs, I am happy to contribute.
Hi @Nicholas-Schaub,
Thank you for reporting this issue. Yes, we are open to contributions! Please feel free to put in a PR.
Thanks.
The VFS change addresses this in part; I will probably expand essentially the same thing to the rest of the TileDB library in a follow-up.