Skip to content

Commit

Permalink
[python/c++] Expose uri, result_order, and column_names for `SO…
Browse files Browse the repository at this point in the history
…MAArray` (#1814) (#1827)

Co-authored-by: nguyenv <[email protected]>
  • Loading branch information
github-actions[bot] and nguyenv authored Oct 25, 2023
1 parent 60c5a44 commit 243563b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
6 changes: 6 additions & 0 deletions apis/python/src/tiledbsoma/pytiledbsoma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ PYBIND11_MODULE(pytiledbsoma, m) {

.def_property_readonly("shape", &SOMAArray::shape)

.def_property_readonly("uri", &SOMAArray::uri)

.def_property_readonly("column_names", &SOMAArray::column_names)

.def_property_readonly("result_order", &SOMAArray::result_order)

.def("get_enum", get_enum)

.def("get_enum_is_ordered", get_enum_is_ordered)
Expand Down
11 changes: 10 additions & 1 deletion libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ class SOMAArray {
return mq_->column_names();
}

/**
* @brief Returns the result order set by the query.
*
* @return ResultOrder
*/
ResultOrder result_order() {
return result_order_;
}

/**
* @brief Read the next chunk of results from the query. If all results
* have already been read, std::nullopt is returned.
Expand Down Expand Up @@ -660,4 +669,4 @@ class SOMAArray {

} // namespace tiledbsoma

#endif // SOMA_ARRAY
#endif // SOMA_ARRAY
34 changes: 24 additions & 10 deletions libtiledbsoma/test/test_soma_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
clib.config_logging("debug")


def test_soma_array_basic_getters():
name = "obs"
uri = os.path.join(SOMA_URI, name)
column_names = [
"soma_joinid",
"obs_id",
"n_genes",
"percent_mito",
"n_counts",
"louvain",
"is_b_cell",
]
result_order = clib.ResultOrder.colmajor

sr = clib.SOMAArray(
uri=uri, name=name, column_names=column_names, result_order=result_order
)

assert sr.uri == uri
assert sr.nnz() == 2638
assert sr.result_order == result_order
assert sr.column_names == column_names


def test_soma_array_obs():
"""Read all values from obs array into an arrow table."""

Expand Down Expand Up @@ -225,16 +249,6 @@ def test_soma_array_column_names():
assert arrow_table.num_columns == 2


def test_nnz():
name = "obs"
uri = os.path.join(SOMA_URI, name)
sr = clib.SOMAArray(uri)

total_cell_count = sr.nnz()

assert total_cell_count == 2638


def test_soma_array_reset():
"""Submit a query with a SOMAArray object, reset the SOMAArray, and submit another query."""

Expand Down

0 comments on commit 243563b

Please sign in to comment.