def astype(self, dtype): if self.dtype == dtype: return self elif (dtype == np.dtype('object') or np.issubdtype(dtype, np.dtype('U').type)): import nvstrings if np.issubdtype(self.dtype, np.signedinteger): if len(self) > 0: dev_array = self.astype('int32').data.mem dev_ptr = get_ctype_ptr(dev_array) null_ptr = None if self.mask is not None: null_ptr = get_ctype_ptr(self.mask.mem) return string.StringColumn( data=nvstrings.itos( dev_ptr, count=len(self), nulls=null_ptr, bdevmem=True ) ) else: return string.StringColumn( data=nvstrings.to_device( [] ) ) elif np.issubdtype(self.dtype, np.floating): raise NotImplementedError( f"Casting object of {self.dtype} dtype " "to str dtype is not yet supported" ) # dev_array = self.astype('float32').data.mem # dev_ptr = get_ctype_ptr(self.data.mem) # return string.StringColumn( # data=nvstrings.ftos(dev_ptr, count=len(self), # bdevmem=True) # ) elif self.dtype == np.dtype('bool'): raise NotImplementedError( f"Casting object of {self.dtype} dtype " "to str dtype is not yet supported" ) # return string.StringColumn( # data=nvstrings.btos(dev_ptr, count=len(self), # bdevmem=True) # ) elif np.issubdtype(dtype, np.datetime64): return self.astype('int64').view( datetime.DatetimeColumn, dtype=dtype, data=self.data.astype(dtype) ) else: col = self.replace(data=self.data.astype(dtype), dtype=np.dtype(dtype)) return col
def test_itos(): s = [0, 103, 1053, 8395739] got = nvstrings.itos(s) expected = nvstrings.to_device(['0', '103', '1053', '8395739']) assert_eq(got, expected)
print(".isdecimal(devptr):",d_arr.copy_to_host()) # print(".isspace():",s.isspace()) s.isspace(d_arr.device_ctypes_pointer.value) print(".isspace(devptr):",d_arr.copy_to_host()) # print(".isnumeric():",s.isnumeric()) s.isnumeric(d_arr.device_ctypes_pointer.value) print(".isnumeric(devptr):",d_arr.copy_to_host()) s = nvstrings.to_device(["1234","ABCDEF","1A2","cafe"]) print(s) print(".htoi()",s.htoi()) arr = np.arange(s.size(),dtype=np.uint32) d_arr = rmm.to_device(arr) s.htoi(d_arr.device_ctypes_pointer.value) print(".htoi(devptr)",d_arr.copy_to_host()) print("itos():",nvstrings.itos(d_arr)) nulls = np.empty(int(s.size()/8)+1, dtype=np.int8) nulls[0] = 11 arr = d_arr.copy_to_host() print("itos(nulls=\\b1011):",nvstrings.itos(arr,nulls=nulls)) s = nvstrings.to_device(["192.168.0.1","10.0.0.1",None,"","hello"]) print(s) print(".ip2int()",s.ip2int()) print(nvstrings.int2ip(s.ip2int())) s = None
def test_itos(): s = [0, 103, 1053, 8395739] got = nvstrings.itos(s) expected = nvstrings.to_device(["0", "103", "1053", "8395739"]) assert_eq(got, expected)