def _window_to_window_sizes(self, window): """ For non-fixed width windows, convert the window argument into window sizes. """ if is_integer(window): return window else: return cudautils.window_sizes_from_offset( self.obj.index._values.data_array_view, window)
def _normalize(self): """ Normalize the *window* and *min_periods* args *window* can be: * An integer, in which case it is the window size. If *min_periods* is unspecified, it is set to be equal to the window size. * A timedelta offset, in which case it is used to generate a column of window sizes to use for each element. If *min_periods* is unspecified, it is set to 1. Only valid for datetime index. """ window, min_periods = self.window, self.min_periods if pd.api.types.is_number(window): # only allow integers if not pd.api.types.is_integer(window): raise ValueError("window must be an integer") if window <= 0: raise ValueError("window cannot be zero or negative") if self.min_periods is None: min_periods = window else: if isinstance(window, numba.cuda.devicearray.DeviceNDArray): # window is a device_array of window sizes self.window = window self.min_periods = min_periods return if not isinstance(self.obj.index, cudf.core.index.DatetimeIndex): raise ValueError( "window must be an integer for " "non datetime index" ) try: window = pd.to_timedelta(window) # to_timedelta will also convert np.arrays etc., if not isinstance(window, pd.Timedelta): raise ValueError window = window.to_timedelta64() except ValueError as e: raise ValueError( "window must be integer or " "convertible to a timedelta" ) from e window = cudautils.window_sizes_from_offset( self.obj.index.as_column().data.mem, window ) if self.min_periods is None: min_periods = 1 self.window = window self.min_periods = min_periods