Skip to content

Commit

Permalink
Fix object_type return value (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
kounelisagis authored Sep 25, 2024
1 parent 5848c27 commit f057c52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tiledb/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1781,14 +1781,14 @@ void init_core(py::module &m) {
m.def("datatype_size", &tiledb_datatype_size);
m.def("as_built_dump", &as_built_dump);
m.def("object_type",
[](const std::string &uri, const Context &ctx) -> py::str {
[](const std::string &uri, const Context &ctx) -> py::object {
tiledb_object_t res;
ctx.handle_error(
tiledb_object_type(ctx.ptr().get(), uri.c_str(), &res));
if (res == TILEDB_ARRAY) {
return std::string("array");
return py::str("array");
} else if (res == TILEDB_GROUP) {
return std::string("group");
return py::str("group");
}
return py::none();
});
Expand Down
15 changes: 15 additions & 0 deletions tiledb/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,18 @@ def create_array(array_name, sparse):
with self.assertRaises(tiledb.TileDBError) as excinfo:
tiledb.ls(dense_arrays_uri, lambda x, y: 1 / 0)
assert "ZeroDivisionError: division by zero" in str(excinfo.value)

def test_object_type(self):
uri = self.path("test_object_type")

# None case
self.assertIsNone(tiledb.object_type(uri))

# Array case
with tiledb.from_numpy(uri, np.arange(0, 5)) as T:
self.assertEqual(tiledb.object_type(uri), "array")
tiledb.Array.delete_array(uri)

# Group case
tiledb.group_create(uri)
self.assertEqual(tiledb.object_type(uri), "group")

0 comments on commit f057c52

Please sign in to comment.