From aec302adc36067e60d8bf9215db168d9b935b366 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 2 Oct 2022 23:26:58 -0400 Subject: [PATCH 1/4] Permit true-ASCII attributes in non-from-pandas dataframes --- tiledb/libtiledb.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 9040ecf3b6..b22334589d 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -1534,6 +1534,7 @@ cdef class Attr(object): if isinstance(dtype, str) and dtype == "ascii": tiledb_dtype = TILEDB_STRING_ASCII ncells = TILEDB_VAR_NUM + var = True else: _dtype = np.dtype(dtype) tiledb_dtype, ncells = array_type_ncells(_dtype) From efb50088838bf8e276861da7d7a17de825e9f8ba Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 4 Oct 2022 15:48:51 -0400 Subject: [PATCH 2/4] code-review feedback --- tiledb/tests/test_libtiledb.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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_)) From 4464b82c9bdb445c1a21ff6a5c1f7186610da3e8 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 4 Oct 2022 15:49:26 -0400 Subject: [PATCH 3/4] code-review feedback --- tiledb/libtiledb.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index b22334589d..327f69fb18 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -1534,7 +1534,8 @@ cdef class Attr(object): if isinstance(dtype, str) and dtype == "ascii": tiledb_dtype = TILEDB_STRING_ASCII ncells = TILEDB_VAR_NUM - var = True + if var is None: + var = True else: _dtype = np.dtype(dtype) tiledb_dtype, ncells = array_type_ncells(_dtype) From 222f4e9a9ce91d3848b91cd844c99fc42bf2ec81 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 4 Oct 2022 15:51:30 -0400 Subject: [PATCH 4/4] code-review feedback --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) 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)