diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 5213120b33f06..61902ede045ef 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1647,6 +1647,7 @@ Timezones - Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`) - Bug in :meth:`DatetimeIndex.to_period` where a timezone aware index was converted to UTC first before creating :class:`PeriodIndex` (:issue:`22905`) - Bug in :meth:`DataFrame.tz_localize`, :meth:`DataFrame.tz_convert`, :meth:`Series.tz_localize`, and :meth:`Series.tz_convert` where ``copy=False`` would mutate the original argument inplace (:issue:`6326`) +- Bug in :meth:`DataFrame.max` and :meth:`DataFrame.min` with ``axis=1`` where a :class:`Series` with ``NaN`` would be returned when all columns contained the same timezone (:issue:`10390`) Offsets ^^^^^^^ diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7bbbdd70e062e..309fb3b841461 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -49,6 +49,7 @@ find_common_type) from pandas.core.dtypes.common import ( is_dict_like, + is_datetime64tz_dtype, is_object_dtype, is_extension_type, is_extension_array_dtype, @@ -7390,7 +7391,9 @@ def f(x): return op(x, axis=axis, skipna=skipna, **kwds) # exclude timedelta/datetime unless we are uniform types - if axis == 1 and self._is_mixed_type and self._is_datelike_mixed_type: + if (axis == 1 and self._is_datelike_mixed_type + and (not self._is_homogeneous_type + and not is_datetime64tz_dtype(self.dtypes[0]))): numeric_only = True if numeric_only is None: diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index d27308029fa19..b269fca6f9ea6 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -135,6 +135,19 @@ def test_nanops(self): assert obj.argmin(skipna=False) == -1 assert obj.argmax(skipna=False) == -1 + @pytest.mark.parametrize('op, expected_col', [ + ['max', 'a'], ['min', 'b'] + ]) + def test_same_tz_min_max_axis_1(self, op, expected_col): + # GH 10390 + df = DataFrame(pd.date_range('2016-01-01 00:00:00', periods=3, + tz='UTC'), + columns=['a']) + df['b'] = df.a.subtract(pd.Timedelta(seconds=3600)) + result = getattr(df, op)(axis=1) + expected = df[expected_col] + tm.assert_series_equal(result, expected) + class TestSeriesReductions(object): # Note: the name TestSeriesReductions indicates these tests