Exemple #1
0
def nanmax(values, axis=None, skipna=True):
    values, mask, dtype, dtype_max = _get_values(values,
                                                 skipna,
                                                 fill_value_typ='-inf')

    # numpy 1.6.1 workaround in Python 3.x
    if is_object_dtype(values) and compat.PY3:

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(builtins.max, apply_ax, values)
        else:
            try:
                result = builtins.max(values)
            except:
                result = np.nan
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            try:
                result = ensure_float(values.sum(axis, dtype=dtype_max))
                result.fill(np.nan)
            except:
                result = np.nan
        else:
            result = values.max(axis)

    result = _wrap_results(result, dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #2
0
def nanmax(values, axis=None, skipna=True):
    values, mask, dtype = _get_values(values, skipna, fill_value_typ='-inf')

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_ and compat.PY3):

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(builtins.max, apply_ax, values)
        else:
            try:
                result = builtins.max(values)
            except:
                result = np.nan
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            try:
                result = com.ensure_float(values.sum(axis))
                result.fill(np.nan)
            except:
                result = np.nan
        else:
            result = values.max(axis)

    result = _wrap_results(result, dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #3
0
def _nanmax(values, axis=None, skipna=True):
    mask = isnull(values)

    dtype = values.dtype

    if skipna and _na_ok_dtype(dtype):
        values = values.copy()
        np.putmask(values, mask, -np.inf)

    values = _view_if_needed(values)

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_
            and sys.version_info[0] >= 3):  # pragma: no cover
        import __builtin__

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(__builtin__.max, apply_ax, values)
        else:
            result = __builtin__.max(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.max(axis)

    result = _wrap_results(result,dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #4
0
    def shift(self, periods, offset=None, timeRule=None):
        """
        Shift the underlying series of the DataMatrix and Series objects within
        by given number (positive or negative) of periods.

        Parameters
        ----------
        periods : int (+ or -)
            Number of periods to move
        offset : DateOffset, optional
            Increment to use from datetools module
        timeRule : string
            Time rule to use by name

        Returns
        -------
        DataMatrix
        """
        if periods == 0:
            return self

        if timeRule is not None and offset is None:
            offset = datetools.getOffset(timeRule)

        if offset is None:
            indexer = self._shift_indexer(periods)
            new_values = self.values.take(indexer, axis=0)
            new_index = self.index

            new_values = common.ensure_float(new_values)

            if periods > 0:
                new_values[:periods] = NaN
            else:
                new_values[periods:] = NaN
        else:
            new_index = self.index.shift(periods, offset)
            new_values = self.values.copy()

        if self.objects is not None:
            shifted_objects = self.objects.shift(periods,
                                                 offset=offset,
                                                 timeRule=timeRule)

            shifted_objects.index = new_index
        else:
            shifted_objects = None

        return DataMatrix(data=new_values,
                          index=new_index,
                          columns=self.columns,
                          objects=shifted_objects)
Exemple #5
0
    def shift(self, periods, offset=None, timeRule=None):
        """
        Shift the underlying series of the DataMatrix and Series objects within
        by given number (positive or negative) of periods.

        Parameters
        ----------
        periods : int (+ or -)
            Number of periods to move
        offset : DateOffset, optional
            Increment to use from datetools module
        timeRule : string
            Time rule to use by name

        Returns
        -------
        DataMatrix
        """
        if periods == 0:
            return self

        if timeRule is not None and offset is None:
            offset = datetools.getOffset(timeRule)

        if offset is None:
            indexer = self._shift_indexer(periods)
            new_values = self.values.take(indexer, axis=0)
            new_index = self.index

            new_values = common.ensure_float(new_values)

            if periods > 0:
                new_values[:periods] = NaN
            else:
                new_values[periods:] = NaN
        else:
            new_index = self.index.shift(periods, offset)
            new_values = self.values.copy()

        if self.objects is not None:
            shifted_objects = self.objects.shift(periods, offset=offset,
                                                 timeRule=timeRule)

            shifted_objects.index = new_index
        else:
            shifted_objects = None

        return DataMatrix(data=new_values, index=new_index,
                          columns=self.columns, objects=shifted_objects)
Exemple #6
0
def nanmin(values, axis=None, skipna=True):
    values, mask, dtype = _get_values(values, skipna, fill_value_typ = '+inf')

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_ and compat.PY3):
        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(builtins.min, apply_ax, values)
        else:
            result = builtins.min(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.min(axis)

    result = _wrap_results(result,dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #7
0
def nanmin(values, axis=None, skipna=True):
    values, mask, dtype = _get_values(values, skipna, fill_value_typ = '+inf')

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_
            and sys.version_info[0] >= 3):  # pragma: no cover
        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(builtins.min, apply_ax, values)
        else:
            result = builtins.min(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.min(axis)

    result = _wrap_results(result,dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #8
0
def _nanmax(values, axis=None, skipna=True):
    values, mask, dtype = _get_values(values, skipna, fill_value_typ ='-inf')

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_
            and sys.version_info[0] >= 3):  # pragma: no cover
        import __builtin__

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(__builtin__.max, apply_ax, values)
        else:
            result = __builtin__.max(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.max(axis)

    result = _wrap_results(result,dtype)
    return _maybe_null_out(result, axis, mask)
Exemple #9
0
def _nanmax(values, axis=None, skipna=True):
    mask = isnull(values)

    dtype = values.dtype

    if skipna and not issubclass(dtype.type, (np.integer, np.datetime64)):
        values = values.copy()
        np.putmask(values, mask, -np.inf)

    if issubclass(dtype.type, np.datetime64):
        values = values.view(np.int64)

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_
            and sys.version_info[0] >= 3):  # pragma: no cover
        import __builtin__

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(__builtin__.max, apply_ax, values)
        else:
            result = __builtin__.max(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.max(axis)

    if issubclass(dtype.type, np.datetime64):
        if not isinstance(result, np.ndarray):
            result = lib.Timestamp(result)
        else:
            result = result.view(dtype)

    return _maybe_null_out(result, axis, mask)
Exemple #10
0
def _nanmax(values, axis=None, skipna=True):
    mask = isnull(values)

    dtype = values.dtype

    if skipna and not issubclass(dtype.type, (np.integer, np.datetime64)):
        values = values.copy()
        np.putmask(values, mask, -np.inf)

    if issubclass(dtype.type, np.datetime64):
        values = values.view(np.int64)

    # numpy 1.6.1 workaround in Python 3.x
    if (values.dtype == np.object_
            and sys.version_info[0] >= 3):  # pragma: no cover
        import __builtin__

        if values.ndim > 1:
            apply_ax = axis if axis is not None else 0
            result = np.apply_along_axis(__builtin__.max, apply_ax, values)
        else:
            result = __builtin__.max(values)
    else:
        if ((axis is not None and values.shape[axis] == 0)
                or values.size == 0):
            result = com.ensure_float(values.sum(axis))
            result.fill(np.nan)
        else:
            result = values.max(axis)

    if issubclass(dtype.type, np.datetime64):
        if not isinstance(result, np.ndarray):
            result = lib.Timestamp(result)
        else:
            result = result.view(dtype)

    return _maybe_null_out(result, axis, mask)