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

Closes #1012 .astype() method #1160

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions arkouda/pdarrayclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,28 @@ def rotr(self, other) -> pdarray:
Rotate bits right by <other>.
"""
return rotr(self, other)

def astype(self, dtype) -> pdarray:
"""
Cast values of pdarray to provided dtype

Parameters
__________
dtype: np.dtype or str
Dtype to cast to

Returns
_______
ak.pdarray
An arkouda pdarray with values converted to the specified data type

Notes
_____
This is essentially shorthand for ak.cast(x, '<dtype>') where x is a pdarray.
"""
from arkouda.numeric import cast as akcast

return akcast(self, dtype)

def to_ndarray(self) -> np.ndarray:
"""
Expand Down
22 changes: 22 additions & 0 deletions arkouda/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,28 @@ def _comp_to_ndarray(self, comp: str) -> np.ndarray:
dt = dt.newbyteorder('<')
return np.frombuffer(rep_msg, dt).copy()

def astype(self, dtype) -> pdarray:
"""
Cast values of Strings object to provided dtype

Parameters
__________
dtype: np.dtype or str
Dtype to cast to

Returns
_______
ak.pdarray
An arkouda pdarray with values converted to the specified data type

Notes
_____
This is essentially shorthand for ak.cast(x, '<dtype>') where x is a pdarray.
"""
from arkouda.numeric import cast as akcast

return akcast(self, dtype)

@typechecked
def save(self, prefix_path : str, dataset : str='strings_array',
mode : str='truncate', save_offsets : bool = True) -> str:
Expand Down