From 117f3b735153720998a383dd0bbe47ec5ab08434 Mon Sep 17 00:00:00 2001 From: Ethan DeBandi <16845933+Ethan-DeBandi99@users.noreply.github.com> Date: Mon, 28 Feb 2022 08:44:51 -0500 Subject: [PATCH] Added as-type method to Strings and pdarrayclass to add support for .astype() --- arkouda/pdarrayclass.py | 22 ++++++++++++++++++++++ arkouda/strings.py | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/arkouda/pdarrayclass.py b/arkouda/pdarrayclass.py index 9ac9b7b9d0..003f806a04 100755 --- a/arkouda/pdarrayclass.py +++ b/arkouda/pdarrayclass.py @@ -854,6 +854,28 @@ def rotr(self, other) -> pdarray: Rotate bits right by . """ 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, '') where x is a pdarray. + """ + from arkouda.numeric import cast as akcast + + return akcast(self, dtype) def to_ndarray(self) -> np.ndarray: """ diff --git a/arkouda/strings.py b/arkouda/strings.py index 6648f53318..eae060cf48 100755 --- a/arkouda/strings.py +++ b/arkouda/strings.py @@ -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, '') 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: