Skip to content

Commit 7fa40ca

Browse files
committed
handle min/max correctly for datetimelikes
1 parent 6651a3f commit 7fa40ca

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

pandas/core/arrays/base.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,7 @@ def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None,
735735
-------
736736
scalar
737737
"""
738-
739-
# we dispatchh to the nanops operations
740-
return op(self, axis=axis, skipna=skipna)
738+
raise AbstractMethodError(self)
741739

742740

743741
class ExtensionScalarOpsMixin(ExtensionOpsMixin):

pandas/core/arrays/datetimelike.py

+36
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,42 @@ def _validate_frequency(cls, index, freq, **kwargs):
342342
'does not conform to passed frequency {passed}'
343343
.format(infer=inferred, passed=freq.freqstr))
344344

345+
# ------------------------------------------------------------------
346+
# Reduction Methods
347+
348+
def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None,
349+
filter_type=None, **kwargs):
350+
"""Return a scalar result of performing the op
351+
352+
Parameters
353+
----------
354+
op : callable
355+
function to apply to the array
356+
name : str
357+
name of the function
358+
axis : int, default 0
359+
axis over which to apply, defined as 0 currently
360+
skipna : bool, default True
361+
if True, skip NaN values
362+
numeric_only : bool, optional
363+
if True, only perform numeric ops
364+
filter_type : str, optional
365+
kwargs : dict
366+
367+
Returns
368+
-------
369+
scalar
370+
"""
371+
# if we have a reduction op already defined, use it
372+
# this is important for min/max where tz's must be preserved
373+
# and nanops is not geared towards this
374+
# TODO(jreback): we are ignoring skipna
375+
if hasattr(self, name):
376+
return getattr(self, name)()
377+
378+
# we dispatch to the nanops operations
379+
return op(self, axis=axis, skipna=skipna)
380+
345381
# ------------------------------------------------------------------
346382
# Arithmetic Methods
347383

pandas/core/dtypes/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,8 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
12361236
if arr_or_dtype is None:
12371237
return False
12381238
tipo = _get_dtype_type(arr_or_dtype)
1239-
return issubclass(tipo, (np.datetime64, np.timedelta64))
1239+
return (issubclass(tipo, (np.datetime64, np.timedelta64)) or
1240+
is_datetime64tz_dtype(arr_or_dtype))
12401241

12411242

12421243
def _is_unorderable_exception(e):

pandas/tests/dtypes/test_common.py

+2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ def test_is_datetime_or_timedelta_dtype():
388388
assert not com.is_datetime_or_timedelta_dtype(np.array(['a', 'b']))
389389

390390
assert com.is_datetime_or_timedelta_dtype(np.datetime64)
391+
assert com.is_datetime_or_timedelta_dtype(
392+
DatetimeTZDtype("ns", "US/Eastern"))
391393
assert com.is_datetime_or_timedelta_dtype(np.timedelta64)
392394
assert com.is_datetime_or_timedelta_dtype(
393395
np.array([], dtype=np.timedelta64))

0 commit comments

Comments
 (0)