Skip to content

min and max of timedelta64 #5690

Closed
Closed
@cancan101

Description

@cancan101

related #5689

On pandas v12:

I thought this was fixed in #2990, but:

both of these:

pd.DataFrame(pd.Series((np.array([np.timedelta64(3000000000),np.timedelta64(3000000000)])))).min()

and

pd.Series((np.array([np.timedelta64(3000000000),np.timedelta64(3000000000)]))).min()

produce:

/usr/lib64/python2.7/site-packages/pandas/core/series.py in min(self, axis, out, skipna, level)
   1509         if level is not None:
   1510             return self._agg_by_level('min', level=level, skipna=skipna)
-> 1511         return nanops.nanmin(self.values, skipna=skipna)
   1512 
   1513     @Substitution(name='maximum', shortname='max',

/usr/lib64/python2.7/site-packages/pandas/core/nanops.py in f(values, axis, skipna, **kwds)
     78                     result = alt(values, axis=axis, skipna=skipna, **kwds)
     79             except Exception:
---> 80                 result = alt(values, axis=axis, skipna=skipna, **kwds)
     81 
     82             return result

/usr/lib64/python2.7/site-packages/pandas/core/nanops.py in nanmin(values, axis, skipna)
    279 @bottleneck_switch()
    280 def nanmin(values, axis=None, skipna=True):
--> 281     values, mask, dtype = _get_values(values, skipna, fill_value_typ = '+inf')
    282 
    283     # numpy 1.6.1 workaround in Python 3.x

/usr/lib64/python2.7/site-packages/pandas/core/nanops.py in _get_values(values, skipna, fill_value, fill_value_typ, isfinite, copy)
    130         mask = _isfinite(values)
    131     else:
--> 132         mask = isnull(values)
    133 
    134     dtype    = values.dtype

/usr/lib64/python2.7/site-packages/pandas/core/common.py in isnull(obj)
     59         given which of the element is null.
     60     """
---> 61     return _isnull(obj)
     62 
     63 

/usr/lib64/python2.7/site-packages/pandas/core/common.py in _isnull_new(obj)
     68     from pandas.core.generic import PandasContainer
     69     if isinstance(obj, np.ndarray):
---> 70         return _isnull_ndarraylike(obj)
     71     elif isinstance(obj, PandasContainer):
     72         # TODO: optimize for DataFrame, etc.

/usr/lib64/python2.7/site-packages/pandas/core/common.py in _isnull_ndarraylike(obj)
    157     else:
    158         # -np.isfinite(obj)
--> 159         result = np.isnan(obj)
    160     return result
    161 

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

I get the same Error with max as well.

median appears to work, although the type is incorrect:

In [144]:
pd.DataFrame(pd.Series((np.array([np.timedelta64(3000000000),np.timedelta64(3000000000)])))).median()

Out[144]:
0    3000000000
dtype: float64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions