Skip to content

Commit 22d30fe

Browse files
authored
Allow Setting ascii in column_type For from_pandas/from_csv (#999)
1 parent 8e61f3a commit 22d30fe

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## API Changes
77
* Addition of `ArraySchema.version` to get version of array schema [#949](https://github.com/TileDB-Inc/TileDB-Py/pull/949)
88
* Deprecate `coords_filters` from `ArraySchema` [#993](https://github.com/TileDB-Inc/TileDB-Py/pull/993)
9+
* Allow setting `ascii` in `column_type` for `from_pandas`/`from_csv` [#999](https://github.com/TileDB-Inc/TileDB-Py/pull/999)
910

1011
# TileDB-Py 0.13.1 Release Notes
1112

tiledb/dataframe_.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def from_values(cls, array_like, varlen_types=()):
112112
def from_dtype(cls, dtype, varlen_types=()):
113113
from pandas.api import types as pd_types
114114

115+
if dtype == "ascii":
116+
return cls("ascii", var=True)
117+
115118
dtype = pd_types.pandas_dtype(dtype)
116119
# Note: be careful if you rearrange the order of the following checks
117120

tiledb/tests/test_pandas_dataframe.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,21 @@ def test_tile_and_cell_order(self, tile_order, cell_order):
13341334
with tiledb.open(uri_from_csv) as A:
13351335
tm.assert_frame_equal(df, A.df[:])
13361336

1337+
def test_set_ascii_dtype(self):
1338+
df = make_dataframe_basic1()
1339+
1340+
uri_char = self.path("test_set_ascii_dtype_char")
1341+
tiledb.from_pandas(uri_char, df, sparse=True)
1342+
with tiledb.open(uri_char) as A:
1343+
assert A.attr("x").dtype == np.dtype("S")
1344+
assert not A.attr("x").isascii
1345+
1346+
uri_ascii = self.path("test_set_ascii_dtype_ascii")
1347+
tiledb.from_pandas(uri_ascii, df, sparse=True, column_types={"x": "ascii"})
1348+
with tiledb.open(uri_ascii) as A:
1349+
assert A.attr("x").dtype == np.dtype("S")
1350+
assert A.attr("x").isascii
1351+
13371352

13381353
class TestFromPandasOptions(DiskTestCase):
13391354
def test_filters_options(self):

0 commit comments

Comments
 (0)