Skip to content

Commit

Permalink
[python] Deprecate result_order='auto' for DenseNDArray reads
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Jan 27, 2025
1 parent 5cef89d commit 7f72e93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion apis/python/src/tiledbsoma/_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import annotations

import warnings
from typing import List, Sequence, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -190,7 +191,7 @@ def read(
The coordinates for slicing the array.
result_order:
Order of read results.
This can be one of 'row-major', 'col-major', or 'auto'.
This can be one of 'row-major' (default) or 'column-major'
partitions:
An optional :class:`ReadPartitions` hint to indicate
how results should be organized.
Expand Down Expand Up @@ -220,6 +221,15 @@ def read(
# all, in which case the best we can do is use the schema shape.
handle: clib.SOMADenseNDArray = self._handle._handle

if result_order == options.ResultOrder.AUTO:
warnings.warn(
"The use of 'result_order=\"auto\"' is deprecated and will be "
"removed in future versions. Please use 'row-order' (the default "
"if no option is provided) or 'col-order' instead.",
DeprecationWarning,
)
result_order = somacore.ResultOrder.ROW_MAJOR

ned = []
for dim_name in handle.dimension_names:
dtype = np.dtype(self.schema.field(dim_name).type.to_pandas_dtype())
Expand Down
2 changes: 1 addition & 1 deletion apis/python/src/tiledbsoma/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def dense_indices_to_shape(
dense_index_to_shape(coord, extent)
for coord, extent in zip_longest(coords, array_shape)
)
if result_order is somacore.ResultOrder.ROW_MAJOR:
if result_order == somacore.ResultOrder.ROW_MAJOR:
return shape
return tuple(reversed(shape))

Expand Down
17 changes: 17 additions & 0 deletions apis/python/tests/test_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,20 @@ def test_pass_configs(tmp_path):
"sm.io_concurrency_level": "1",
}
)


def test_read_result_order(tmp_path):
uri = tmp_path.as_posix()
data = np.arange(0, 8).reshape(4, 2)

with soma.DenseNDArray.create(uri, type=pa.int8(), shape=(4, 2)) as A:
A.write((slice(None), slice(None)), pa.Tensor.from_numpy(data))

with soma.DenseNDArray.open(uri, mode="r") as A:
assert np.array_equal(A.read(), data)
assert np.array_equal(A.read(result_order="row-major"), data)
assert np.array_equal(A.read(result_order="column-major"), data.T)
with pytest.warns(
DeprecationWarning, match="The use of 'result_order=\"auto\"' is deprecated"
):
assert np.array_equal(A.read(result_order="auto"), data)

0 comments on commit 7f72e93

Please sign in to comment.