Skip to content

Commit

Permalink
Closes #3709: reshape to return a multi-dimensional array
Browse files Browse the repository at this point in the history
Co-authored-by: drculhane <drculhane@users.noreply.github.com>
  • Loading branch information
ajpotts and drculhane committed Aug 29, 2024
1 parent c36172a commit 48d1530
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 636 deletions.
1 change: 0 additions & 1 deletion arkouda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
del get_versions

from arkouda.numpy import *
from arkouda.array_view import *
from arkouda.client import *
from arkouda.client_dtypes import *
from arkouda.pdarrayclass import *
Expand Down
471 changes: 0 additions & 471 deletions arkouda/array_view.py

This file was deleted.

50 changes: 28 additions & 22 deletions arkouda/pdarrayclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ def _create_scalar_array(value):
)


def _reshape(array: pdarray, shape: Tuple[int, ...]):
"""
Reshape the pdarray to the specified shape
Requires the ManipulationMsg server module
"""
return create_pdarray(
generic_msg(
cmd=f"reshape<{array.dtype},{array.ndim},{len(shape)}>",
args={
"name": array,
"shape": shape,
},
),
)
# def _reshape(array: pdarray, shape: Tuple[int, ...]):
# """
# Reshape the pdarray to the specified shape
#
# Requires the ManipulationMsg server module
# """
# return create_pdarray(
# generic_msg(
# cmd=f"reshape<{array.dtype},{array.ndim},{len(shape)}>",
# args={
# "name": array,
# "shape": shape,
# },
# ),
# )


def _squeeze(array: pdarray, degen_axes: List[int]):
Expand Down Expand Up @@ -980,7 +980,7 @@ def __getitem__(self, key):
if len(rs) > 0:
shape.append(rs.pop(0))

return _reshape(ret_array, tuple(shape))
return ret_array.reshape(shape)
else:
return ret_array

Expand Down Expand Up @@ -1147,7 +1147,7 @@ def __setitem__(self, key, value):
)

# reshape to add singleton dimensions as needed
_value_r = _reshape(_value, slice_shape)
_value_r = _value.reshape(slice_shape)
else:
raise ValueError(
f"value array must not have more dimensions ({_value.ndim}) than the"
Expand Down Expand Up @@ -1754,18 +1754,24 @@ def reshape(self, *shape, order="row_major"):
Returns
-------
ArrayView
An arrayview object with the data from the array but with the new shape
pdarray
a pdarray with the same data, reshaped to the new shape
"""
from arkouda.array_view import ArrayView

# allows the elements of the shape parameter to be passed in as separate arguments
# For example, a.reshape(10, 11) is equivalent to a.reshape((10, 11))
if len(shape) == 1:
shape = shape[0]
elif not isinstance(shape, pdarray):
shape = [i for i in shape]
return ArrayView(base=self, shape=shape, order=order)
return create_pdarray(
generic_msg(
cmd=f"reshape<{self.dtype},{self.ndim},{len(shape)}>",
args={
"name": self.name,
"shape": shape,
},
),
)

def to_ndarray(self) -> np.ndarray:
"""
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ testpaths =
tests/array_api/stats_functions.py
tests/array_api/util_functions.py
tests/alignment_test.py
tests/array_view_test.py
tests/bigint_agg_test.py
tests/bitops_test.py
tests/categorical_test.py
Expand All @@ -37,6 +36,7 @@ testpaths =
tests/numpy/numpy_test.py
tests/operator_test.py
tests/pdarray_creation_test.py
tests/pdarrayclass_test.py
tests/random_test.py
tests/regex_test.py
tests/scipy/scipy_test.py
Expand Down
141 changes: 0 additions & 141 deletions tests/array_view_test.py

This file was deleted.

1 change: 1 addition & 0 deletions tests/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@ def test_unsanitized_dataset_names(self, hdf_test_base_tmp):
ak.to_hdf(my_arrays, f"{tmp_dirname}/bad_dataset_names")
ak.read_hdf(f"{tmp_dirname}/bad_dataset_names*")


def test_hdf_groupby(self, hdf_test_base_tmp):
# test for categorical and multiple keys
string = ak.array(["a", "b", "a", "b", "c"])
Expand Down
13 changes: 13 additions & 0 deletions tests/pdarrayclass_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

import arkouda as ak


class TestPdarrayClass:

@pytest.mark.skip_if_max_rank_less_than(3)
def test_reshape(self):
a = ak.arange(4)
r = a.reshape((2, 2))
assert r.shape == [2, 2]
assert isinstance(r, ak.pdarray)

0 comments on commit 48d1530

Please sign in to comment.