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

Handle empty string passed to Query condition #1774

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
4 changes: 2 additions & 2 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ cdef class DenseArrayImpl(Array):
q = PyQuery(self._ctx_(), self, tuple(attr_names), tuple(), <int32_t>layout, False)
self.pyquery = q

if cond is not None:
if cond is not None and cond != "":
from .query_condition import QueryCondition

if isinstance(cond, str):
Expand Down Expand Up @@ -2921,7 +2921,7 @@ cdef class SparseArrayImpl(Array):
q = PyQuery(self._ctx_(), self, tuple(attr_names), tuple(), <int32_t>layout, False)
self.pyquery = q

if cond is not None:
if cond is not None and cond != "":
from .query_condition import QueryCondition

if isinstance(cond, str):
Expand Down
30 changes: 30 additions & 0 deletions tiledb/tests/test_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,33 @@ def test_delete_with_string_dimension(self):
with tiledb.open(path, "r") as A:
assert_array_equal(A[:]["d"], [b"c"])
assert_array_equal(A[:]["a"], [30])

def test_qc_dense_empty(self):
path = self.path("test_qc_dense_empty")

dom = tiledb.Domain(tiledb.Dim(name="d", domain=(1, 1), tile=1, dtype=np.uint8))
attrs = [tiledb.Attr(name="a", dtype=np.uint8)]
schema = tiledb.ArraySchema(domain=dom, attrs=attrs, sparse=False)
tiledb.Array.create(path, schema)

with tiledb.open(path, mode="w") as A:
A[:] = np.arange(1)

with tiledb.open(path) as A:
assert_array_equal(A.query(cond="")[:]["a"], [0])

def test_qc_sparse_empty(self):
path = self.path("test_qc_sparse_empty")

dom = tiledb.Domain(
tiledb.Dim(name="d", domain=(1, 10), tile=1, dtype=np.uint8)
)
attrs = [tiledb.Attr(name="a", dtype=np.uint8)]
schema = tiledb.ArraySchema(domain=dom, attrs=attrs, sparse=True)
tiledb.Array.create(path, schema)

with tiledb.open(path, mode="w") as A:
A[1] = {"a": np.arange(1)}

with tiledb.open(path) as A:
assert_array_equal(A.query(cond="")[:]["a"], [0])