Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the object_type return value for the None case #2073

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading