Skip to content

Commit 8ce64b7

Browse files
mroeschkejreback
authored andcommitted
BUG: DataFrame.min/max with axis=1 and uniform datetime64[ns, tz] types does not return NaNs (#24759)
1 parent 57a6f44 commit 8ce64b7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ Timezones
16481648
- Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`)
16491649
- Bug in :meth:`DatetimeIndex.to_period` where a timezone aware index was converted to UTC first before creating :class:`PeriodIndex` (:issue:`22905`)
16501650
- 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`)
1651+
- 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`)
16511652

16521653
Offsets
16531654
^^^^^^^

pandas/core/frame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
find_common_type)
5050
from pandas.core.dtypes.common import (
5151
is_dict_like,
52+
is_datetime64tz_dtype,
5253
is_object_dtype,
5354
is_extension_type,
5455
is_extension_array_dtype,
@@ -7390,7 +7391,9 @@ def f(x):
73907391
return op(x, axis=axis, skipna=skipna, **kwds)
73917392

73927393
# exclude timedelta/datetime unless we are uniform types
7393-
if axis == 1 and self._is_mixed_type and self._is_datelike_mixed_type:
7394+
if (axis == 1 and self._is_datelike_mixed_type
7395+
and (not self._is_homogeneous_type
7396+
and not is_datetime64tz_dtype(self.dtypes[0]))):
73947397
numeric_only = True
73957398

73967399
if numeric_only is None:

pandas/tests/reductions/test_reductions.py

+13
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ def test_nanops(self):
135135
assert obj.argmin(skipna=False) == -1
136136
assert obj.argmax(skipna=False) == -1
137137

138+
@pytest.mark.parametrize('op, expected_col', [
139+
['max', 'a'], ['min', 'b']
140+
])
141+
def test_same_tz_min_max_axis_1(self, op, expected_col):
142+
# GH 10390
143+
df = DataFrame(pd.date_range('2016-01-01 00:00:00', periods=3,
144+
tz='UTC'),
145+
columns=['a'])
146+
df['b'] = df.a.subtract(pd.Timedelta(seconds=3600))
147+
result = getattr(df, op)(axis=1)
148+
expected = df[expected_col]
149+
tm.assert_series_equal(result, expected)
150+
138151

139152
class TestSeriesReductions(object):
140153
# Note: the name TestSeriesReductions indicates these tests

0 commit comments

Comments
 (0)