23
23
from .common import (
24
24
DiskTestCase ,
25
25
assert_captured ,
26
+ assert_dict_arrays_equal ,
26
27
assert_subarrays_equal ,
27
28
assert_unordered_equal ,
28
29
fx_sparse_cell_order , # noqa: F401
@@ -923,8 +924,8 @@ def assert_ts(timestamp, result):
923
924
assert_ts ((timestamps [2 ], None ), A * 3 )
924
925
assert_ts ((timestamps [2 ], None ), A * 3 )
925
926
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 " )
928
929
schema = tiledb .ArraySchema (
929
930
domain = tiledb .Domain (
930
931
tiledb .Dim (name = "dim0" , dtype = np .uint32 , domain = (1 , 4 ))
@@ -949,6 +950,48 @@ def test_open_attr(self):
949
950
assert_array_equal (A [:], np .array ((1 , 2 , 3 , 4 )))
950
951
assert list (A .multi_index [:].keys ()) == ["x" ]
951
952
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
+
952
995
def test_ncell_attributes (self ):
953
996
dom = tiledb .Domain (tiledb .Dim (domain = (0 , 9 ), tile = 10 , dtype = int ))
954
997
attr = tiledb .Attr (dtype = [("" , np .int32 ), ("" , np .int32 ), ("" , np .int32 )])
0 commit comments