Skip to content

Commit

Permalink
[python] Throw error in SOMAVFSFilebuf.open on file-not-found (#3565)…
Browse files Browse the repository at this point in the history
… (#3569)

Co-authored-by: nguyenv <[email protected]>
  • Loading branch information
github-actions[bot] and nguyenv authored Jan 16, 2025
1 parent 5d491c5 commit afaab5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apis/python/src/tiledbsoma/soma_vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ void load_soma_vfs(py::module& m) {
.def(
"open",
[](SOMAVFSFilebuf& buf, const std::string& uri) {
return buf.open(uri, std::ios::in);
auto fb = buf.open(uri, std::ios::in);
if (fb == nullptr) {
TPY_ERROR_LOC(
std::format("URI {} is not a valid URI", uri));
}
return fb;
},
py::call_guard<py::gil_scoped_release>())
.def("read", &SOMAVFSFilebuf::read, "size"_a = -1)
Expand Down
5 changes: 5 additions & 0 deletions apis/python/tests/test_basic_anndata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,3 +1528,8 @@ def test_decat_append(tmp_path):
obs_table.column("bool_enum").to_pylist()
== bool_enum_values_over + bool_enum_values_under
)


def test_from_h5ad_bad_uri():
with pytest.raises(tiledbsoma.SOMAError, match="URI /nonesuch is not a valid URI"):
next(tiledbsoma.io._util.read_h5ad("/nonesuch").gen)

0 comments on commit afaab5c

Please sign in to comment.