Skip to content

Commit

Permalink
fix incorrect type handling (#3375) (#3378)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruce Martin <bruce.martin@tiledb.com>
  • Loading branch information
github-actions[bot] and bkmartinjr authored Nov 22, 2024
1 parent a58df6a commit f6fd3f1
Showing 1 changed file with 14 additions and 6 deletions.
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

0 comments on commit f6fd3f1

Please sign in to comment.