@@ -425,65 +425,34 @@ def nansem(values, axis=None, skipna=True, ddof=1):
425
425
return np .sqrt (var ) / np .sqrt (count )
426
426
427
427
428
- @bottleneck_switch ()
429
- def nanmin (values , axis = None , skipna = True ):
430
- values , mask , dtype , dtype_max = _get_values (values , skipna ,
431
- fill_value_typ = '+inf' )
432
-
433
- # numpy 1.6.1 workaround in Python 3.x
434
- if is_object_dtype (values ) and compat .PY3 :
435
- if values .ndim > 1 :
436
- apply_ax = axis if axis is not None else 0
437
- result = np .apply_along_axis (builtins .min , apply_ax , values )
438
- else :
439
- try :
440
- result = builtins .min (values )
441
- except :
442
- result = np .nan
443
- else :
428
+ def _nanminmax (meth , fill_value_typ ):
429
+ @bottleneck_switch ()
430
+ def reduction (values , axis = None , skipna = True ):
431
+ values , mask , dtype , dtype_max = _get_values (
432
+ values ,
433
+ skipna ,
434
+ fill_value_typ = fill_value_typ ,
435
+ )
436
+
444
437
if ((axis is not None and values .shape [axis ] == 0 )
445
438
or values .size == 0 ):
446
439
try :
447
- result = ensure_float (values . sum (axis , dtype = dtype_max ) )
440
+ result = getattr (values , meth ) (axis , dtype = dtype_max )
448
441
result .fill (np .nan )
449
442
except :
450
443
result = np .nan
451
444
else :
452
- result = values . min (axis )
445
+ result = getattr ( values , meth ) (axis )
453
446
454
- result = _wrap_results (result , dtype )
455
- return _maybe_null_out (result , axis , mask )
447
+ result = _wrap_results (result , dtype )
448
+ return _maybe_null_out (result , axis , mask )
456
449
450
+ reduction .__name__ = 'nan' + meth
451
+ return reduction
457
452
458
- @bottleneck_switch ()
459
- def nanmax (values , axis = None , skipna = True ):
460
- values , mask , dtype , dtype_max = _get_values (values , skipna ,
461
- fill_value_typ = '-inf' )
462
453
463
- # numpy 1.6.1 workaround in Python 3.x
464
- if is_object_dtype (values ) and compat .PY3 :
465
-
466
- if values .ndim > 1 :
467
- apply_ax = axis if axis is not None else 0
468
- result = np .apply_along_axis (builtins .max , apply_ax , values )
469
- else :
470
- try :
471
- result = builtins .max (values )
472
- except :
473
- result = np .nan
474
- else :
475
- if ((axis is not None and values .shape [axis ] == 0 )
476
- or values .size == 0 ):
477
- try :
478
- result = ensure_float (values .sum (axis , dtype = dtype_max ))
479
- result .fill (np .nan )
480
- except :
481
- result = np .nan
482
- else :
483
- result = values .max (axis )
484
-
485
- result = _wrap_results (result , dtype )
486
- return _maybe_null_out (result , axis , mask )
454
+ nanmin = _nanminmax ('min' , fill_value_typ = '+inf' )
455
+ nanmax = _nanminmax ('max' , fill_value_typ = '-inf' )
487
456
488
457
489
458
def nanargmax (values , axis = None , skipna = True ):
@@ -637,7 +606,7 @@ def _maybe_null_out(result, axis, mask):
637
606
else :
638
607
result = result .astype ('f8' )
639
608
result [null_mask ] = np .nan
640
- else :
609
+ elif result is not tslib . NaT :
641
610
null_mask = mask .size - mask .sum ()
642
611
if null_mask == 0 :
643
612
result = np .nan
0 commit comments