diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index f07f054c2216b..83067ffd64c79 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -718,7 +718,8 @@ def reduction(values, axis=None, skipna=True, mask=None): result = np.nan else: result = getattr(values, meth)(axis) - if is_integer(result) and result == _int64_max: + if (is_integer(result) and is_datetime_or_timedelta_dtype(dtype) + and result == _int64_max): result = tslibs.iNaT result = _wrap_results(result, dtype) diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index cd6a81230492c..1fb7de3730b55 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -510,7 +510,18 @@ def test_dt_timetz_accessor(self, tz_naive_fixture): result = s.dt.timetz tm.assert_series_equal(result, expected) - def test_minmax_nat(self): - series = pd.Series([pd.NaT, pd.NaT]) - assert series.min() is pd.NaT - assert series.max() is pd.NaT + @pytest.mark.parametrize('nat', [ + pd.Series([pd.NaT, pd.NaT]), + pd.Series([pd.NaT, pd.Timedelta('nat')]), + pd.Series([pd.Timedelta('nat'), pd.Timedelta('nat')])]) + def test_minmax_nat_series(self, nat): + assert nat.min() is pd.NaT + assert nat.max() is pd.NaT + + @pytest.mark.parametrize('nat', [ + pd.DataFrame([pd.NaT, pd.NaT]), + pd.DataFrame([pd.NaT, pd.Timedelta('nat')]), + pd.DataFrame([pd.Timedelta('nat'), pd.Timedelta('nat')])]) + def test_minmax_nat_dataframe(self, nat): + assert nat.min()[0] is pd.NaT + assert nat.max()[0] is pd.NaT