diff --git a/tiledb/core.cc b/tiledb/core.cc index 1b20bba631..fc8af53ea5 100644 --- a/tiledb/core.cc +++ b/tiledb/core.cc @@ -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(); }); diff --git a/tiledb/tests/test_util.py b/tiledb/tests/test_util.py index 6882c4dd35..297e18800f 100644 --- a/tiledb/tests/test_util.py +++ b/tiledb/tests/test_util.py @@ -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")