Skip to content

Commit

Permalink
[c++] Corner-case bug in extend-enumeration logic (#2897)
Browse files Browse the repository at this point in the history
* Add Python unit-test coverage

* run `make format`

* [c++] Corner-case bug in extend-enumeration logic

* lint
  • Loading branch information
johnkerl authored Aug 16, 2024
1 parent a61795a commit bdba3c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 3 additions & 6 deletions apis/python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,7 @@ def test_timestamped_schema_evolve(tmp_path):
atbl = pa.Table.from_pydict(
{
"soma_joinid": [3, 4],
"myenum": pd.Series(["b", "c"], dtype="category"),
# TODO https://github.com/single-cell-data/TileDB-SOMA/issues/2896
# "myenum": pd.Series(['b', 'b'], dtype='category'),
# Perhaps leave this t=3 as-is, and add a write of ['c', 'c'] at t=4.
"myenum": pd.Series(["b", "b"], dtype="category"),
}
)
with soma.DataFrame.open(uri, "w", tiledb_timestamp=3) as sdf:
Expand All @@ -1661,8 +1658,8 @@ def test_timestamped_schema_evolve(tmp_path):

with soma.DataFrame.open(uri, tiledb_timestamp=3) as sdf:
table = sdf.read().concat()
assert table["myenum"].to_pylist() == ["a", "b", "a", "b", "c"]
assert table["myenum"].to_pylist() == ["a", "b", "a", "b", "b"]

with soma.DataFrame.open(uri) as sdf:
table = sdf.read().concat()
assert table["myenum"].to_pylist() == ["a", "b", "a", "b", "c"]
assert table["myenum"].to_pylist() == ["a", "b", "a", "b", "b"]
11 changes: 11 additions & 0 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ bool SOMAArray::_extend_and_evolve_schema_str(
index_schema->format = ArrowAdapter::to_arrow_format(disk_index_type)
.data();
return true;
} else {
// Example:
//
// * Already on storage/schema there are values a,b,c with indices
// 0,1,2.
// * User appends values b,c which, within the Arrow data coming in
// from the user, have indices 0,1.
// * We need to remap those to 1,2.

SOMAArray::_remap_indexes(
column_name, enmr, enums_in_write, index_schema, index_array);
}
return false;
}
Expand Down

0 comments on commit bdba3c3

Please sign in to comment.