Skip to content

Commit 8c6f2db

Browse files
committed
Fixed datetimelike-max
Working around pandas-dev#24265
1 parent 87101bf commit 8c6f2db

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pandas/core/arrays/datetimelike.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1341,10 +1341,21 @@ def min(self, skipna=True):
13411341

13421342
def max(self, skipna=True):
13431343
# TODO: skipna is broken with max.
1344-
result = nanops.nanmax(self.asi8, skipna=skipna, mask=self.isna())
1345-
if isna(result):
1346-
# Period._from_ordinal does not handle np.nan gracefully
1344+
# See https://github.com/pandas-dev/pandas/issues/24265
1345+
mask = self.isna()
1346+
if skipna:
1347+
values = self[~mask].asi8
1348+
elif mask.any():
1349+
return NaT
1350+
else:
1351+
values = self.asi8
1352+
1353+
if not len(values):
1354+
# short-circut for empty max / min
13471355
return NaT
1356+
# Do not pass mask, since it's maybe not the right shape.
1357+
result = nanops.nanmax(values, skipna=skipna)
1358+
# Don't have to worry about NA `result`, since no NA went in.
13481359
return self._box_func(result)
13491360

13501361

0 commit comments

Comments
 (0)