Repository: TileDB-Inc/TileDB-Py
Pull request #2141 (2025-01-11 00:56:59)

Increase the data size to avoid random failures in `test_qc_enumeration`
`test_qc_enumeration` has been observed to [fail](https://github.com/TileDB-Inc/TileDB-Py/actions/runs/12718853000/job/35458017629#step:12:1147) randomly. The data of the Array in that test is random, and its domain is relatively small; `(1, 100)`. As seen in the logs, this results in the `result` array containing only fill values, indicating that the condition is too strict for the Array we have. Increasing the size of the Array should resolve the issue permanently.


Patch:
diff --git a/tiledb/dense_array.py b/tiledb/dense_array.py
index 17224809..b9050f31 100644
--- a/tiledb/dense_array.py
+++ b/tiledb/dense_array.py
@@ -165,8 +165,19 @@ class DenseArrayImpl(Array):
         ...                {"a1": np.zeros(5)})
 
         """
-        if not self.isopen or self.mode != "r":
-            raise tiledb.TileDBError("DenseArray must be opened in read mode")
+        if not self.isopen:
+            raise tiledb.TileDBError("Array is not opened")
+
+        if self.mode == "w":
+            raise tiledb.TileDBError(
+                "Write mode is not supported for queries on Dense Arrays"
+            )
+        elif self.mode == "d":
+            raise tiledb.TileDBError(
+                "Delete mode is not supported for queries on Dense Arrays"
+            )
+        elif self.mode != "r":
+            raise tiledb.TileDBError("Invalid mode for queries on Dense Arrays")
 
         return Query(
             self,
@@ -215,8 +226,19 @@ class DenseArrayImpl(Array):
         ...                 OrderedDict({'a1': np.zeros(5)}))
 
         """
-        if not self.isopen or self.mode != "r":
-            raise tiledb.TileDBError("DenseArray must be opened in read mode")
+        if not self.isopen:
+            raise tiledb.TileDBError("Array is not opened")
+
+        if self.mode == "w":
+            raise tiledb.TileDBError(
+                "Write mode is not supported for subarray queries on Dense Arrays"
+            )
+        elif self.mode == "d":
+            raise tiledb.TileDBError(
+                "Delete mode is not supported for subarray queries on Dense Arrays"
+            )
+        elif self.mode != "r":
+            raise tiledb.TileDBError("Invalid mode for subarray query on Dense Array")
 
         layout = lt.LayoutType.UNORDERED
         if order is None or order == "C":
diff --git a/tiledb/sparse_array.py b/tiledb/sparse_array.py
index 255dc2e7..a44c5ba8 100644
--- a/tiledb/sparse_array.py
+++ b/tiledb/sparse_array.py
@@ -372,10 +372,15 @@ class SparseArrayImpl(Array):
         ...                    OrderedDict({'a1': np.array([1, 2])}))
 
         """
-        if not self.isopen or self.mode not in ("r", "d"):
+        if not self.isopen:
+            raise tiledb.TileDBError("Array is not opened")
+
+        if self.mode == "w":
             raise tiledb.TileDBError(
-                "SparseArray must be opened in read or delete mode"
+                "Write mode is not supported for queries on Sparse Arrays"
             )
+        elif self.mode not in ("r", "d"):
+            raise tiledb.TileDBError("Invalid mode for queries on Sparse Arrays")
 
         # backwards compatibility
         _coords = coords
@@ -484,8 +489,15 @@ class SparseArrayImpl(Array):
         """
         from .subarray import Subarray
 
-        if not self.isopen or self.mode not in ("r", "d"):
-            raise tiledb.TileDBError("SparseArray is not opened in read or delete mode")
+        if not self.isopen:
+            raise tiledb.TileDBError("Array is not opened")
+
+        if self.mode == "w":
+            raise tiledb.TileDBError(
+                "Write mode is not supported for subarray queries on Sparse Arrays"
+            )
+        elif self.mode not in ("r", "d"):
+            raise tiledb.TileDBError("Invalid mode for subarray query on Sparse Array")
 
         layout = lt.LayoutType.UNORDERED
         if order is None or order == "U":


Test patch:
diff --git a/tiledb/tests/test_query_condition.py b/tiledb/tests/test_query_condition.py
index a3c3f157..e41d319b 100644
--- a/tiledb/tests/test_query_condition.py
+++ b/tiledb/tests/test_query_condition.py
@@ -874,7 +874,7 @@ class QueryConditionTest(DiskTestCase):
 
     def test_qc_enumeration(self):
         uri = self.path("test_qc_enumeration")
-        dom = tiledb.Domain(tiledb.Dim(domain=(1, 8), tile=1))
+        dom = tiledb.Domain(tiledb.Dim(domain=(1, 100), tile=1))
         enum1 = tiledb.Enumeration("enmr1", True, [0, 1, 2])
         enum2 = tiledb.Enumeration("enmr2", True, ["a", "bb", "ccc"])
         attr1 = tiledb.Attr("attr1", dtype=np.int32, enum_label="enmr1")
@@ -884,8 +884,8 @@ class QueryConditionTest(DiskTestCase):
         )
         tiledb.Array.create(uri, schema)
 
-        data1 = np.random.randint(0, 3, 8)
-        data2 = np.random.randint(0, 3, 8)
+        data1 = np.random.randint(0, 3, 100)
+        data2 = np.random.randint(0, 3, 100)
 
         with tiledb.open(uri, "w") as A:
             A[:] = {"attr1": data1, "attr2": data2}
@@ -1022,7 +1022,7 @@ class QueryDeleteTest(DiskTestCase):
 
             with pytest.raises(
                 tiledb.TileDBError,
-                match="SparseArray must be opened in read or delete mode",
+                match="Write mode is not supported for queries on Sparse Arrays",
             ):
                 A.query(cond=qc).submit()
 
@@ -1052,7 +1052,7 @@ class QueryDeleteTest(DiskTestCase):
         with tiledb.open(path, "d") as A:
             with pytest.raises(
                 tiledb.TileDBError,
-                match="DenseArray must be opened in read mode",
+                match="Delete mode is not supported for queries on Dense Arrays",
             ):
                 A.query()