Skip to content

Commit 90f9ee9

Browse files
authored
Fix repr For datetime Dimensions By Casting tile To int (#998)
* Use `tile`'s `repr()` Not `str()` for `Dim.__repr__` * Update HISTORY.md
1 parent 22d30fe commit 90f9ee9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Bug Fixes
44
* Fix default validity for write to nullable attribute [#994]((https://github.com/TileDB-Inc/TileDB-Py/pull/994)
55
* Reduce query time for dense var-length arrays by including extra offset element in initial buffer allocation [#1005](https://github.com/TileDB-Inc/TileDB-Py/pull/1005)
6+
* Fix round-trippable repr for dimension tile [#998](https://github.com/TileDB-Inc/TileDB-Py/pull/998)
7+
68
## API Changes
79
* Addition of `ArraySchema.version` to get version of array schema [#949](https://github.com/TileDB-Inc/TileDB-Py/pull/949)
810
* Deprecate `coords_filters` from `ArraySchema` [#993](https://github.com/TileDB-Inc/TileDB-Py/pull/993)

tiledb/libtiledb.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,8 +1904,7 @@ cdef class Dim(object):
19041904

19051905
# for consistency, print `var=True` for string-like types
19061906
varlen = "" if not self.dtype in (np.str_, np.bytes_) else ", var=True"
1907-
1908-
return "Dim(name={0!r}, domain={1!s}, tile='{2!s}', dtype='{3!s}'{4}{5})" \
1907+
return "Dim(name={0!r}, domain={1!s}, tile={2!r}, dtype='{3!s}'{4}{5})" \
19091908
.format(self.name, self.domain, self.tile, self.dtype, varlen, filters_str)
19101909

19111910
def _repr_html_(self) -> str:

tiledb/tests/test_libtiledb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,6 +4256,7 @@ def test_dim_repr(self):
42564256
dim_test_imports = textwrap.dedent(
42574257
"""
42584258
from tiledb import Dim, FilterList, GzipFilter
4259+
import numpy
42594260
from numpy import float64
42604261
"""
42614262
)
@@ -4273,6 +4274,17 @@ def test_dim_repr(self):
42734274
dim = tiledb.Dim(name="d1", dtype=dtype, **opt_kwarg)
42744275
self.assertEqual(eval(repr(dim), g), dim)
42754276

4277+
# test datetime
4278+
g = dict()
4279+
exec(dim_test_imports, g)
4280+
dim = tiledb.Dim(
4281+
name="d1",
4282+
domain=(np.datetime64("2010-01-01"), np.datetime64("2020")),
4283+
tile=2,
4284+
dtype=np.datetime64("", "D"),
4285+
)
4286+
self.assertEqual(eval(repr(dim), g), dim)
4287+
42764288
def test_arrayschema_repr(self, sparse_cell_order):
42774289
filters = tiledb.FilterList([tiledb.ZstdFilter(-1)])
42784290
for sparse in [False, True]:

0 commit comments

Comments
 (0)