diff --git a/HISTORY.md b/HISTORY.md index d9113a761a..dca9ee9e8d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ # In Progress ## API Changes +* Permit true-ASCII attributes in non-from-pandas dataframes [#1337](https://github.com/TileDB-Inc/TileDB-Py/pull/1337) * Addition of `Array.upgrade_version` to upgrade array to latest version [#1334](https://github.com/TileDB-Inc/TileDB-Py/pull/1334) * Attributes in query conditions no longer need to be passed to `Array.query`'s `attr` arg [#1333](https://github.com/TileDB-Inc/TileDB-Py/pull/1333) diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 9040ecf3b6..327f69fb18 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -1534,6 +1534,8 @@ cdef class Attr(object): if isinstance(dtype, str) and dtype == "ascii": tiledb_dtype = TILEDB_STRING_ASCII ncells = TILEDB_VAR_NUM + if var is None: + var = True else: _dtype = np.dtype(dtype) tiledb_dtype, ncells = array_type_ncells(_dtype) diff --git a/tiledb/tests/test_libtiledb.py b/tiledb/tests/test_libtiledb.py index d322d77971..98fa5a06ae 100644 --- a/tiledb/tests/test_libtiledb.py +++ b/tiledb/tests/test_libtiledb.py @@ -526,7 +526,15 @@ def test_ascii_attribute(self, sparse, capfd): dom = tiledb.Domain( tiledb.Dim(name="d", domain=(1, 4), tile=1, dtype=np.uint32) ) - attrs = [tiledb.Attr(name="A", dtype="ascii", var=True)] + + with pytest.raises(TypeError) as exc_info: + tiledb.Attr(name="A", dtype="ascii", var=False) + assert ( + str(exc_info.value) == "dtype is not compatible with var-length attribute" + ) + + attrs = [tiledb.Attr(name="A", dtype="ascii")] + schema = tiledb.ArraySchema(domain=dom, attrs=attrs, sparse=sparse) tiledb.Array.create(path, schema) @@ -547,6 +555,7 @@ def test_ascii_attribute(self, sparse, capfd): assert A.schema.nattr == 1 A.schema.dump() assert_captured(capfd, "Type: STRING_ASCII") + assert A.schema.attr("A").isvar assert A.schema.attr("A").dtype == np.bytes_ assert A.schema.attr("A").isascii assert_array_equal(A[:]["A"], np.asarray(ascii_data, dtype=np.bytes_))