@@ -360,6 +360,37 @@ def data(self, data):
360360 )
361361 self ._data = data
362362
363+ def astype (self , dtype , casting = "unsafe" , copy = True ):
364+ """
365+ Copy of the Variable object, with data cast to a specified type.
366+
367+ Parameters
368+ ----------
369+ dtype : str or dtype
370+ Typecode or data-type to which the array is cast.
371+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
372+ Controls what kind of data casting may occur. Defaults to 'unsafe'
373+ for backwards compatibility.
374+
375+ * 'no' means the data types should not be cast at all.
376+ * 'equiv' means only byte-order changes are allowed.
377+ * 'safe' means only casts which can preserve values are allowed.
378+ * 'same_kind' means only safe casts or casts within a kind,
379+ like float64 to float32, are allowed.
380+ * 'unsafe' means any data conversions may be done.
381+ copy : bool, optional
382+ By default, astype always returns a newly allocated array. If this
383+ is set to False and the `dtype` requirement is satisfied, the input
384+ array is returned instead of a copy.
385+
386+ See also
387+ --------
388+ np.ndarray.astype
389+ dask.array.Array.astype
390+ """
391+ self .data = duck_array_ops .astype (self .data , dtype , casting = casting , copy = copy )
392+ return self
393+
363394 def load (self , ** kwargs ):
364395 """Manually trigger loading of this variable's data from disk or a
365396 remote source into memory and return this variable.
0 commit comments