Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-1.15] [python] Fix incorrect type handling in ExperimentAxisQuery sparse reader #3378

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions apis/python/src/tiledbsoma/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,16 @@ def _read_as_csr(
var_joinids = var_joinids_arr.to_numpy()
nnz = matrix.nnz

d0_dtype = np.int32 if len(obs_joinids) > np.iinfo(np.int32).max else np.int64
d1_dtype = np.int32 if len(var_joinids) > np.iinfo(np.int32).max else np.int64
# if able, downcast from int64 - reduces working memory
index_dtype = (
np.int32
if max(len(obs_joinids), len(var_joinids)) < np.iinfo(np.int32).max
else np.int64
)
pa_schema = pa.schema(
[
pa.field("soma_dim_0", pa.from_numpy_dtype(d0_dtype)),
pa.field("soma_dim_1", pa.from_numpy_dtype(d1_dtype)),
pa.field("soma_dim_0", pa.from_numpy_dtype(index_dtype)),
pa.field("soma_dim_1", pa.from_numpy_dtype(index_dtype)),
matrix.schema.field("soma_data"),
]
)
Expand All @@ -821,8 +825,12 @@ def _read_and_reindex(
def _reindex(batch: pa.RecordBatch) -> pa.RecordBatch:
return pa.RecordBatch.from_pydict(
{
"soma_dim_0": indexer.by_obs(batch["soma_dim_0"]).astype(d0_dtype),
"soma_dim_1": indexer.by_var(batch["soma_dim_1"]).astype(d1_dtype),
"soma_dim_0": indexer.by_obs(batch["soma_dim_0"]).astype(
index_dtype
),
"soma_dim_1": indexer.by_var(batch["soma_dim_1"]).astype(
index_dtype
),
"soma_data": batch["soma_data"],
},
schema=pa_schema,
Expand Down
Loading