diff --git a/apis/python/src/tiledbsoma/_dense_nd_array.py b/apis/python/src/tiledbsoma/_dense_nd_array.py index e370ee1235..6d6087edee 100644 --- a/apis/python/src/tiledbsoma/_dense_nd_array.py +++ b/apis/python/src/tiledbsoma/_dense_nd_array.py @@ -8,6 +8,7 @@ from __future__ import annotations +import warnings from typing import List, Sequence, Tuple, Union import numpy as np @@ -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. @@ -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()) diff --git a/apis/python/src/tiledbsoma/_util.py b/apis/python/src/tiledbsoma/_util.py index 8d0611d5ac..1d1b0c11c8 100644 --- a/apis/python/src/tiledbsoma/_util.py +++ b/apis/python/src/tiledbsoma/_util.py @@ -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)) diff --git a/apis/python/tests/test_dense_nd_array.py b/apis/python/tests/test_dense_nd_array.py index 17d378c53a..3b62e6b191 100644 --- a/apis/python/tests/test_dense_nd_array.py +++ b/apis/python/tests/test_dense_nd_array.py @@ -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)