Skip to content

Commit

Permalink
Fix buffer exclusion when specifying attribute subset
Browse files Browse the repository at this point in the history
  • Loading branch information
ihnorton committed Jun 26, 2020
1 parent 163705c commit 35b5d30
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tiledb/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ class PyQuery {
// schema.attributes() is unordered, but we need to return ordered results
for (size_t attr_idx = 0; attr_idx < schema.attribute_num(); attr_idx++) {
auto attr = schema.attribute(attr_idx);
if (std::find(attrs_.begin(), attrs_.end(), attr.name()) == attrs_.end()) {
continue;
}
alloc_buffer(attr.name());
}

Expand Down
2 changes: 1 addition & 1 deletion tiledb/multirange_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __getitem__(self, idx):

schema = self.schema
dom = self.schema.domain
attr_names = tuple(self.schema.attr(i).name for i in range(self.schema.nattr))
attr_names = tuple(self.schema.attr(i)._internal_name for i in range(self.schema.nattr))

coords = None
order = 'C' # TILEDB_ROW_MAJOR
Expand Down
13 changes: 12 additions & 1 deletion tiledb/tests/test_libtiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ def test_multiple_attributes(self):
with tiledb.DenseArray(self.path("foo"), mode='w', ctx=ctx) as T:
T[:] = V

import tiledb.core as core
with tiledb.DenseArray(self.path("foo"), mode='r', ctx=ctx) as T:
R = T[:]
assert_array_equal(V["ints"], R["ints"])
Expand All @@ -1155,6 +1156,16 @@ def test_multiple_attributes(self):
with self.assertRaises(tiledb.TileDBError):
T.query(attrs=("unknown"))[:]

# Ensure that query only returns specified attributes
q = core.PyQuery(ctx, T, ("ints",), False, 0)
q.set_ranges([[(0,1)]])
q.submit()
r = q.results()
self.assertTrue("ints" in r)
self.assertTrue("floats" not in r)
del q


with tiledb.DenseArray(self.path("foo"), mode='w', ctx=ctx) as T:
# check error ncells length
V["ints"] = V["ints"][1:2].copy()
Expand All @@ -1166,6 +1177,7 @@ def test_multiple_attributes(self):
with self.assertRaises(tiledb.TileDBError):
T[:] = V


def test_array_2d_s1(self):
# This array is currently read back with dtype object
A = np.array([['A', 'B'], ['C', '']], dtype='S')
Expand Down Expand Up @@ -2835,7 +2847,6 @@ def test_tiledb_py_0_6_anon_attr(self):
os.path.join(fragment_path, "_attr_.tdb"),
os.path.join(fragment_path, "__attr.tdb")
)

with tiledb.open(path) as A:
self.assertEqual(A.schema.attr(0).name, "")
self.assertEqual(A.schema.attr(0)._internal_name, "__attr")
Expand Down
4 changes: 2 additions & 2 deletions tiledb/tests/test_multi_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_multirange_1d_dense_vectorized(self):
dom = tiledb.Domain(tiledb.Dim(domain=(0, 999), tile=1000,
dtype=np.uint32, ctx=ctx),
ctx=ctx)
attrs = tiledb.Attr(name="U", dtype=np.float64, ctx=ctx)
attrs = tiledb.Attr(name='', dtype=np.float64, ctx=ctx)

schema = tiledb.ArraySchema(domain=dom, attrs=(attrs,), sparse=False, ctx=ctx)
tiledb.DenseArray.create(path, schema)
Expand All @@ -600,7 +600,7 @@ def test_multirange_1d_dense_vectorized(self):
res = A.multi_index[idxs]
assert_array_equal(
data[idxs],
res['U']
res['']
)

def test_multirange_2d_dense_float(self):
Expand Down

0 comments on commit 35b5d30

Please sign in to comment.