From f057c527ed01da8347709fcfd63bd03043edcb85 Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis <36283973+kounelisagis@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:42:25 +0300 Subject: [PATCH] Fix object_type return value (#2073) Fixes https://app.shortcut.com/tiledb-inc/story/55930 --- tiledb/core.cc | 6 +++--- tiledb/tests/test_util.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) 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")