xarray/core/variable.py
def pad(
        self,
        pad_width: Mapping[Hashable, Union[int, Tuple[int, int]]] = None,
        mode: str = "constant",
        stat_length: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        constant_values: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        end_values: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        reflect_type: str = None,
        **pad_width_kwargs: Any,
    ):
        """
        Return a new Variable with padded data.

        Parameters
        ----------
        pad_width : mapping of hashable to tuple of int
            Mapping with the form of {dim: (pad_before, pad_after)}
            describing the number of values padded along each dimension.
            {dim: pad} is a shortcut for pad_before = pad_after = pad
        mode : str, default: "constant"
            See numpy / Dask docs
        stat_length : int, tuple or mapping of hashable to tuple
            Used in 'maximum', 'mean', 'median', and 'minimum'.  Number of
            values at edge of each axis used to calculate the statistic value.
        constant_values : scalar, tuple or mapping of hashable to tuple
            Used in 'constant'.  The values to set the padded values for each
            axis.
        end_values : scalar, tuple or mapping of hashable to tuple
            Used in 'linear_ramp'.  The values used for the ending value of the
            linear_ramp and that will form the edge of the padded array.
        reflect_type : {"even", "odd"}, optional
            Used in "reflect", and "symmetric".  The "even" style is the
            default with an unaltered reflection around the edge value.  For
            the "odd" style, the extended part of the array is created by
            subtracting the reflected values from two times the edge value.
        **pad_width_kwargs
            One of pad_width or pad_width_kwargs must be provided.

        Returns
        -------
        padded : Variable
            Variable with the same dimensions and attributes but padded data.
        """
        pad_width = either_dict_or_kwargs(pad_width, pad_width_kwargs, "pad")

        # change default behaviour of pad with mode constant
        if mode == "constant" and (
            constant_values is None or constant_values is dtypes.NA
        ):
            dtype, constant_values = dtypes.maybe_promote(self.dtype)
        else:
            dtype = self.dtype

        # create pad_options_kwargs, numpy requires only relevant kwargs to be nonempty
        if isinstance(stat_length, dict):
            stat_length = self._pad_options_dim_to_index(
                stat_length, fill_with_shape=True
            )
        if isinstance(constant_values, dict):
            constant_values = self._pad_options_dim_to_index(constant_values)
        if isinstance(end_values, dict):
            end_values = self._pad_options_dim_to_index(end_values)

        # workaround for bug in Dask's default value of stat_length  https://github.com/dask/dask/issues/5303
        if stat_length is None and mode in ["maximum", "mean", "median", "minimum"]:
            stat_length = [(n, n) for n in self.data.shape]  # type: ignore

        # change integer values to a tuple of two of those values and change pad_width to index
        for k, v in pad_width.items():
            if isinstance(v, numbers.Number):
                pad_width[k] = (v, v)
        pad_width_by_index = self._pad_options_dim_to_index(pad_width)

        # create pad_options_kwargs, numpy/dask requires only relevant kwargs to be nonempty
        pad_option_kwargs = {}
        if stat_length is not None:
            pad_option_kwargs["stat_length"] = stat_length
        if constant_values is not None:
            pad_option_kwargs["constant_values"] = constant_values
        if end_values is not None:
            pad_option_kwargs["end_values"] = end_values
        if reflect_type is not None:
            pad_option_kwargs["reflect_type"] = reflect_type  # type: ignore

        array = duck_array_ops.pad(
            self.data.astype(dtype, copy=False),
            pad_width_by_index,
            mode=mode,
            **pad_option_kwargs,
        )

        return type(self)(self.dims, array)

        Return a new Variable with padded data.

        Parameters
        ----------
        pad_width : mapping of hashable to tuple of int
            Mapping with the form of {dim: (pad_before, pad_after)}
            describing the number of values padded along each dimension.
            {dim: pad} is a shortcut for pad_before = pad_after = pad
        mode : str, default: "constant"
            See numpy / Dask docs
        stat_length : int, tuple or mapping of hashable to tuple
            Used in 'maximum', 'mean', 'median', and 'minimum'.  Number of
            values at edge of each axis used to calculate the statistic value.
        constant_values : scalar, tuple or mapping of hashable to tuple
            Used in 'constant'.  The values to set the padded values for each
            axis.
        end_values : scalar, tuple or mapping of hashable to tuple
            Used in 'linear_ramp'.  The values used for the ending value of the
            linear_ramp and that will form the edge of the padded array.
        reflect_type : {"even", "odd"}, optional
            Used in "reflect", and "symmetric".  The "even" style is the
            default with an unaltered reflection around the edge value.  For
            the "odd" style, the extended part of the array is created by
            subtracting the reflected values from two times the edge value.
        **pad_width_kwargs
            One of pad_width or pad_width_kwargs must be provided.

        Returns
        -------
        padded : Variable
            Variable with the same dimensions and attributes but padded data.
        
Return a new Variable with padded data.
Parameters

pad_width : mapping of hashable to tuple of int
Mapping with the form of {dim: (pad_before, pad_after)}
describing the number of values padded along each dimension.

Returns

padded : Variable
Variable with the same dimensions and attributes but padded data.
Return a new Variable with padded data . Parameters pad_width : mapping of hashable to tuple of int Mapping with the form of { dim : ( pad_before pad_after ) } describing the number of values padded along each dimension . Returns padded : Variable Variable with the same dimensions and attributes but padded data .
def pad(
        self,
        pad_width: Mapping[Hashable, Union[int, Tuple[int, int]]] = None,
        mode: str = "constant",
        stat_length: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        constant_values: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        end_values: Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ] = None,
        reflect_type: str = None,
        **pad_width_kwargs: Any,
    ):
        pad_width = either_dict_or_kwargs(pad_width, pad_width_kwargs, "pad")
        if mode == "constant" and (
            constant_values is None or constant_values is dtypes.NA
        ):
            dtype, constant_values = dtypes.maybe_promote(self.dtype)
        else:
            dtype = self.dtype
        if isinstance(stat_length, dict):
            stat_length = self._pad_options_dim_to_index(
                stat_length, fill_with_shape=True
            )
        if isinstance(constant_values, dict):
            constant_values = self._pad_options_dim_to_index(constant_values)
        if isinstance(end_values, dict):
            end_values = self._pad_options_dim_to_index(end_values)
        if stat_length is None and mode in ["maximum", "mean", "median", "minimum"]:
            stat_length = [(n, n) for n in self.data.shape]  
        for k, v in pad_width.items():
            if isinstance(v, numbers.Number):
                pad_width[k] = (v, v)
        pad_width_by_index = self._pad_options_dim_to_index(pad_width)
        pad_option_kwargs = {}
        if stat_length is not None:
            pad_option_kwargs["stat_length"] = stat_length
        if constant_values is not None:
            pad_option_kwargs["constant_values"] = constant_values
        if end_values is not None:
            pad_option_kwargs["end_values"] = end_values
        if reflect_type is not None:
            pad_option_kwargs["reflect_type"] = reflect_type  
        array = duck_array_ops.pad(
            self.data.astype(dtype, copy=False),
            pad_width_by_index,
            mode=mode,
            **pad_option_kwargs,
        )
        return type(self)(self.dims, array)
def pad ( self , pad_width : Mapping [ Hashable , Union [ int , Tuple [ int , int ] ] ] = None , mode : str = "constant" , stat_length : Union [ int , Tuple [ int , int ] , Mapping [ Hashable , Tuple [ int , int ] ] ] = None , constant_values : Union [ int , Tuple [ int , int ] , Mapping [ Hashable , Tuple [ int , int ] ] ] = None , end_values : Union [ int , Tuple [ int , int ] , Mapping [ Hashable , Tuple [ int , int ] ] ] = None , reflect_type : str = None , ** pad_width_kwargs : Any , ) : pad_width = either_dict_or_kwargs ( pad_width , pad_width_kwargs , "pad" ) if mode == "constant" and ( constant_values is None or constant_values is dtypes . NA ) : dtype , constant_values = dtypes . maybe_promote ( self . dtype ) else : dtype = self . dtype if isinstance ( stat_length , dict ) : stat_length = self . _pad_options_dim_to_index ( stat_length , fill_with_shape = True ) if isinstance ( constant_values , dict ) : constant_values = self . _pad_options_dim_to_index ( constant_values ) if isinstance ( end_values , dict ) : end_values = self . _pad_options_dim_to_index ( end_values ) if stat_length is None and mode in [ "maximum" , "mean" , "median" , "minimum" ] : stat_length = [ ( n , n ) for n in self . data . shape ] for k , v in pad_width . items ( ) : if isinstance ( v , numbers . Number ) : pad_width [ k ] = ( v , v ) pad_width_by_index = self . _pad_options_dim_to_index ( pad_width ) pad_option_kwargs = { } if stat_length is not None : pad_option_kwargs [ "stat_length" ] = stat_length if constant_values is not None : pad_option_kwargs [ "constant_values" ] = constant_values if end_values is not None : pad_option_kwargs [ "end_values" ] = end_values if reflect_type is not None : pad_option_kwargs [ "reflect_type" ] = reflect_type array = duck_array_ops . pad ( self . data . astype ( dtype , copy = False ) , pad_width_by_index , mode = mode , ** pad_option_kwargs , ) return type ( self ) ( self . dims , array )
Return a new Variable with padded data.
Return a new Variable with padded data .
"""
        Return a new Variable with padded data.

        Parameters
        ----------
        pad_width : mapping of hashable to tuple of int
            Mapping with the form of {dim: (pad_before, pad_after)}
            describing the number of values padded along each dimension.
            {dim: pad} is a shortcut for pad_before = pad_after = pad
        mode : str, default: "constant"
            See numpy / Dask docs
        stat_length : int, tuple or mapping of hashable to tuple
            Used in 'maximum', 'mean', 'median', and 'minimum'.  Number of
            values at edge of each axis used to calculate the statistic value.
        constant_values : scalar, tuple or mapping of hashable to tuple
            Used in 'constant'.  The values to set the padded values for each
            axis.
        end_values : scalar, tuple or mapping of hashable to tuple
            Used in 'linear_ramp'.  The values used for the ending value of the
            linear_ramp and that will form the edge of the padded array.
        reflect_type : {"even", "odd"}, optional
            Used in "reflect", and "symmetric".  The "even" style is the
            default with an unaltered reflection around the edge value.  For
            the "odd" style, the extended part of the array is created by
            subtracting the reflected values from two times the edge value.
        **pad_width_kwargs
            One of pad_width or pad_width_kwargs must be provided.

        Returns
        -------
        padded : Variable
            Variable with the same dimensions and attributes but padded data.
        """ # change default behaviour of pad with mode constant # create pad_options_kwargs, numpy requires only relevant kwargs to be nonempty # workaround for bug in Dask's default value of stat_length  https://github.com/dask/dask/issues/5303 # type: ignore # change integer values to a tuple of two of those values and change pad_width to index # create pad_options_kwargs, numpy/dask requires only relevant kwargs to be nonempty # type: ignore
self
pad_width
Mapping[Hashable, Union[int, Tuple[int, int]]]
mode
str
stat_length
Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ]
constant_values
Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ]
end_values
Union[
            int, Tuple[int, int], Mapping[Hashable, Tuple[int, int]]
        ]
reflect_type
str
pad_width_kwargs
Any