@@ -195,6 +195,13 @@ def test_blob_attribute(self):
195
195
attr = tiledb .Attr (name = "foo" , dtype = "blob" )
196
196
self .assertEqual (attr , attr )
197
197
self .assertEqual (attr .dtype , np .bytes_ )
198
+ self .assertTrue (attr .isvar ) # for blobs var is True if not specified
199
+
200
+ attr1 = tiledb .Attr (name = "foo" , dtype = "blob" , var = True )
201
+ self .assertTrue (attr1 .isvar )
202
+
203
+ attr2 = tiledb .Attr (name = "foo" , dtype = "blob" , var = False )
204
+ self .assertFalse (attr2 .isvar )
198
205
199
206
def test_blob_attribute_dump (self , capfd ):
200
207
attr = tiledb .Attr (name = "foo" , dtype = "blob" )
@@ -248,6 +255,65 @@ def test_ascii_attribute(self, sparse, capfd):
248
255
assert A .schema .attr ("A" ).isascii
249
256
assert_array_equal (A [:]["A" ], np .asarray (ascii_data , dtype = np .bytes_ ))
250
257
258
+ @pytest .mark .parametrize ("sparse" , [True , False ])
259
+ def test_fixed_size_blob_attribute (self , sparse ):
260
+ path = self .path ("test_fixed_blob" )
261
+ dom = tiledb .Domain (
262
+ tiledb .Dim (name = "d" , domain = (1 , 4 ), tile = 1 , dtype = np .uint32 )
263
+ )
264
+ attrs = [tiledb .Attr (name = "a" , dtype = "blob" , var = False )]
265
+
266
+ schema = tiledb .ArraySchema (domain = dom , attrs = attrs , sparse = sparse )
267
+ tiledb .Array .create (path , schema )
268
+
269
+ # Fixed-size blob attribute stores single bytes per cell
270
+ blob_data = [b"a" , b"b" , b"c" , b"d" ]
271
+
272
+ with tiledb .open (path , "w" ) as A :
273
+ if sparse :
274
+ A [np .arange (1 , 5 )] = blob_data
275
+ else :
276
+ A [:] = np .asarray (blob_data , dtype = np .bytes_ )
277
+
278
+ with tiledb .open (path , "r" ) as A :
279
+ assert A .schema .nattr == 1
280
+ assert A .schema .attr ("a" ).ncells == 1
281
+ assert not A .schema .attr ("a" ).isvar
282
+ assert A .schema .attr ("a" ).dtype == np .dtype ("|S0" ) # numpy representation
283
+ assert (
284
+ A .schema .attr ("a" )._tiledb_dtype == tiledb .libtiledb .DataType .BLOB
285
+ ) # TileDB type
286
+ assert_array_equal (A [:]["a" ], np .asarray (blob_data , dtype = np .bytes_ ))
287
+
288
+ @pytest .mark .parametrize ("sparse" , [True , False ])
289
+ def test_var_blob_attribute (self , sparse ):
290
+ path = self .path ("test_var_blob" )
291
+ dom = tiledb .Domain (
292
+ tiledb .Dim (name = "d" , domain = (1 , 4 ), tile = 1 , dtype = np .uint32 )
293
+ )
294
+ attrs = [tiledb .Attr (name = "a" , dtype = "blob" , var = True )]
295
+
296
+ schema = tiledb .ArraySchema (domain = dom , attrs = attrs , sparse = sparse )
297
+ tiledb .Array .create (path , schema )
298
+
299
+ # Variable-length blob attribute can store different sized blobs per cell
300
+ blob_data = [b"a" , b"bb" , b"ccc" , b"dddd" ]
301
+
302
+ with tiledb .open (path , "w" ) as A :
303
+ if sparse :
304
+ A [np .arange (1 , 5 )] = blob_data
305
+ else :
306
+ A [:] = blob_data
307
+
308
+ with tiledb .open (path , "r" ) as A :
309
+ assert A .schema .nattr == 1
310
+ assert A .schema .attr ("a" ).isvar
311
+ assert A .schema .attr ("a" ).dtype == np .dtype ("|S0" ) # numpy representation
312
+ assert (
313
+ A .schema .attr ("a" )._tiledb_dtype == tiledb .libtiledb .DataType .BLOB
314
+ ) # TileDB type
315
+ assert_array_equal (A [:]["a" ], np .array (blob_data , dtype = np .bytes_ ))
316
+
251
317
def test_modify_attribute_in_schema (self ):
252
318
path = self .path ("test_modify_attribute_in_schema" )
253
319
tiledb .from_numpy (path , np .random .rand (10 ))
0 commit comments