Exemplo n.º 1
0
def interpolate_2d(values, method='pad', axis=0, limit=None, fill_value=None):
    """
    Copied from the 0.15.2. This did not exist in 0.12.0.

    Differences:
        - Don't depend on pad_2d and backfill_2d to return values
        - Removed dtype kwarg. 0.12.0 did not have this option.
    """
    transf = (lambda x: x) if axis == 0 else (lambda x: x.T)

    # reshape a 1 dim if needed
    ndim = values.ndim
    if values.ndim == 1:
        if axis != 0:  # pragma: no cover
            raise AssertionError("cannot interpolate on a ndim == 1 with "
                                 "axis != 0")
        values = values.reshape(tuple((1, ) + values.shape))

    if fill_value is None:
        mask = None
    else:  # todo create faster fill func without masking
        mask = mask_missing(transf(values), fill_value)

    # Note: pad_2d and backfill_2d work inplace in 0.12.0 and 0.15.2
    # in 0.15.2 they also return a reference to values
    if method == 'pad':
        pad_2d(transf(values), limit=limit, mask=mask)
    else:
        backfill_2d(transf(values), limit=limit, mask=mask)

    # reshape back
    if ndim == 1:
        values = values[0]

    return values
Exemplo n.º 2
0
def interpolate_2d(values, method='pad', axis=0, limit=None, fill_value=None):
    """
    Copied from the 0.15.2. This did not exist in 0.12.0.

    Differences:
        - Don't depend on pad_2d and backfill_2d to return values
        - Removed dtype kwarg. 0.12.0 did not have this option.
    """
    transf = (lambda x: x) if axis == 0 else (lambda x: x.T)

    # reshape a 1 dim if needed
    ndim = values.ndim
    if values.ndim == 1:
        if axis != 0:  # pragma: no cover
            raise AssertionError("cannot interpolate on a ndim == 1 with "
                                 "axis != 0")
        values = values.reshape(tuple((1,) + values.shape))

    if fill_value is None:
        mask = None
    else:  # todo create faster fill func without masking
        mask = mask_missing(transf(values), fill_value)

    # Note: pad_2d and backfill_2d work inplace in 0.12.0 and 0.15.2
    # in 0.15.2 they also return a reference to values
    if method == 'pad':
        pad_2d(transf(values), limit=limit, mask=mask)
    else:
        backfill_2d(transf(values), limit=limit, mask=mask)

    # reshape back
    if ndim == 1:
        values = values[0]

    return values
Exemplo n.º 3
0
    def interpolate(self, method='pad', axis=0, inplace=False, limit=None):
        values = self.values if inplace else self.values.copy()

        if values.ndim != 2:
            raise NotImplementedError

        transf = (lambda x: x) if axis == 0 else (lambda x: x.T)

        if method == 'pad':
            com.pad_2d(transf(values), limit=limit)
        else:
            com.backfill_2d(transf(values), limit=limit)

        return make_block(values, self.items, self.ref_items)
Exemplo n.º 4
0
    def interpolate(self, method="pad", axis=0, inplace=False, limit=None, missing=None):
        values = self.values if inplace else self.values.copy()

        if values.ndim != 2:
            raise NotImplementedError

        transf = (lambda x: x) if axis == 0 else (lambda x: x.T)

        if missing is None:
            mask = None
        else:  # todo create faster fill func without masking
            mask = _mask_missing(transf(values), missing)

        if method == "pad":
            com.pad_2d(transf(values), limit=limit, mask=mask)
        else:
            com.backfill_2d(transf(values), limit=limit, mask=mask)

        return make_block(values, self.items, self.ref_items)
Exemplo n.º 5
0
    def interpolate(self, method='pad', axis=0, inplace=False,
                    limit=None, missing=None):
        values = self.values if inplace else self.values.copy()

        if values.ndim != 2:
            raise NotImplementedError

        transf = (lambda x: x) if axis == 0 else (lambda x: x.T)

        if missing is None:
            mask = None
        else: # todo create faster fill func without masking
            mask = _mask_missing(transf(values), missing)

        if method == 'pad':
            com.pad_2d(transf(values), limit=limit, mask=mask)
        else:
            com.backfill_2d(transf(values), limit=limit, mask=mask)

        return make_block(values, self.items, self.ref_items)