Skip to content

Commit ab4ac0a

Browse files
committed
Modify tests
1 parent a1b91e1 commit ab4ac0a

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

tiledb/tests/test_libtiledb.py

+45-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .common import (
2424
DiskTestCase,
2525
assert_captured,
26+
assert_dict_arrays_equal,
2627
assert_subarrays_equal,
2728
assert_unordered_equal,
2829
fx_sparse_cell_order, # noqa: F401
@@ -923,8 +924,8 @@ def assert_ts(timestamp, result):
923924
assert_ts((timestamps[2], None), A * 3)
924925
assert_ts((timestamps[2], None), A * 3)
925926

926-
def test_open_attr(self):
927-
uri = self.path("test_open_attr")
927+
def test_open_attr_dense(self):
928+
uri = self.path("test_open_attr_dense")
928929
schema = tiledb.ArraySchema(
929930
domain=tiledb.Domain(
930931
tiledb.Dim(name="dim0", dtype=np.uint32, domain=(1, 4))
@@ -949,6 +950,48 @@ def test_open_attr(self):
949950
assert_array_equal(A[:], np.array((1, 2, 3, 4)))
950951
assert list(A.multi_index[:].keys()) == ["x"]
951952

953+
with tiledb.open(uri, attr="x") as A:
954+
q = A.query(cond="x <= 3")
955+
expected = np.array([1, 2, 3, schema.attr("x").fill[0]])
956+
assert_array_equal(q[:], expected)
957+
958+
def test_open_attr_sparse(self):
959+
uri = self.path("test_open_attr_sparse")
960+
schema = tiledb.ArraySchema(
961+
domain=tiledb.Domain(
962+
tiledb.Dim(name="dim0", dtype=np.uint32, domain=(1, 4))
963+
),
964+
attrs=(
965+
tiledb.Attr(name="x", dtype=np.int32),
966+
tiledb.Attr(name="y", dtype=np.int32),
967+
),
968+
sparse=True,
969+
)
970+
tiledb.Array.create(uri, schema)
971+
972+
with tiledb.open(uri, mode="w") as A:
973+
A[[1, 2, 3, 4]] = {"x": np.array((1, 2, 3, 4)), "y": np.array((5, 6, 7, 8))}
974+
975+
with self.assertRaises(KeyError):
976+
tiledb.open(uri, attr="z")
977+
978+
with self.assertRaises(KeyError):
979+
tiledb.open(uri, attr="dim0")
980+
981+
with tiledb.open(uri, attr="x") as A:
982+
expected = OrderedDict(
983+
[("dim0", np.array([1, 2, 3, 4])), ("x", np.array([1, 2, 3, 4]))]
984+
)
985+
assert_dict_arrays_equal(A[:], expected)
986+
assert list(A.multi_index[:].keys()) == ["dim0", "x"]
987+
988+
with tiledb.open(uri, attr="x") as A:
989+
q = A.query(cond="x <= 3")
990+
expected = OrderedDict(
991+
[("dim0", np.array([1, 2, 3])), ("x", np.array([1, 2, 3]))]
992+
)
993+
assert_dict_arrays_equal(q[:], expected)
994+
952995
def test_ncell_attributes(self):
953996
dom = tiledb.Domain(tiledb.Dim(domain=(0, 9), tile=10, dtype=int))
954997
attr = tiledb.Attr(dtype=[("", np.int32), ("", np.int32), ("", np.int32)])

0 commit comments

Comments
 (0)