Skip to content

Commit 54cc935

Browse files
authored
Permit true-ASCII attributes in non-from-pandas dataframes (#1337)
* When creating an attribute of dtype "ascii", `var` should be defaulted to `True`
1 parent eb95922 commit 54cc935

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# In Progress
22

33
## API Changes
4+
* Permit true-ASCII attributes in non-from-pandas dataframes [#1337](https://github.com/TileDB-Inc/TileDB-Py/pull/1337)
45
* Addition of `Array.upgrade_version` to upgrade array to latest version [#1334](https://github.com/TileDB-Inc/TileDB-Py/pull/1334)
56
* 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)
67
* `ArraySchemaEvolution` checks context's last error for error message [#1335](https://github.com/TileDB-Inc/TileDB-Py/pull/1335)

tiledb/libtiledb.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,8 @@ cdef class Attr(object):
15341534
if isinstance(dtype, str) and dtype == "ascii":
15351535
tiledb_dtype = TILEDB_STRING_ASCII
15361536
ncells = TILEDB_VAR_NUM
1537+
if var is None:
1538+
var = True
15371539
else:
15381540
_dtype = np.dtype(dtype)
15391541
tiledb_dtype, ncells = array_type_ncells(_dtype)

tiledb/tests/test_libtiledb.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,15 @@ def test_ascii_attribute(self, sparse, capfd):
526526
dom = tiledb.Domain(
527527
tiledb.Dim(name="d", domain=(1, 4), tile=1, dtype=np.uint32)
528528
)
529-
attrs = [tiledb.Attr(name="A", dtype="ascii", var=True)]
529+
530+
with pytest.raises(TypeError) as exc_info:
531+
tiledb.Attr(name="A", dtype="ascii", var=False)
532+
assert (
533+
str(exc_info.value) == "dtype is not compatible with var-length attribute"
534+
)
535+
536+
attrs = [tiledb.Attr(name="A", dtype="ascii")]
537+
530538
schema = tiledb.ArraySchema(domain=dom, attrs=attrs, sparse=sparse)
531539
tiledb.Array.create(path, schema)
532540

@@ -547,6 +555,7 @@ def test_ascii_attribute(self, sparse, capfd):
547555
assert A.schema.nattr == 1
548556
A.schema.dump()
549557
assert_captured(capfd, "Type: STRING_ASCII")
558+
assert A.schema.attr("A").isvar
550559
assert A.schema.attr("A").dtype == np.bytes_
551560
assert A.schema.attr("A").isascii
552561
assert_array_equal(A[:]["A"], np.asarray(ascii_data, dtype=np.bytes_))

0 commit comments

Comments
 (0)