@@ -329,13 +329,18 @@ def _get_counts_nanvar(mask, axis, ddof):
329329 return count , d
330330
331331
332- @disallow ('M8' )
332+ @disallow ('M8' , 'm8' )
333333@bottleneck_switch (ddof = 1 )
334334def nanvar (values , axis = None , skipna = True , ddof = 1 ):
335- if not _is_floating_dtype (values ):
336- values = values .astype ('f8' )
335+
336+ # we are going to allow timedelta64[ns] here
337+ # but NOT going to coerce them to the Timedelta type
338+ # as this could cause overflow
339+ # so var cannot be computed (but std can!)
337340
338341 mask = isnull (values )
342+ if not _is_floating_dtype (values ):
343+ values = values .astype ('f8' )
339344
340345 count , d = _get_counts_nanvar (mask , axis , ddof )
341346
@@ -347,13 +352,13 @@ def nanvar(values, axis=None, skipna=True, ddof=1):
347352 XX = _ensure_numeric ((values ** 2 ).sum (axis ))
348353 return np .fabs ((XX - X ** 2 / count ) / d )
349354
350-
355+ @ disallow ( 'M8' , 'm8' )
351356def nansem (values , axis = None , skipna = True , ddof = 1 ):
352357 var = nanvar (values , axis , skipna , ddof = ddof )
353358
359+ mask = isnull (values )
354360 if not _is_floating_dtype (values ):
355361 values = values .astype ('f8' )
356- mask = isnull (values )
357362 count , _ = _get_counts_nanvar (mask , axis , ddof )
358363
359364 return np .sqrt (var )/ np .sqrt (count )
@@ -442,12 +447,13 @@ def nanargmin(values, axis=None, skipna=True):
442447 return result
443448
444449
445- @disallow ('M8' )
450+ @disallow ('M8' , 'm8' )
446451def nanskew (values , axis = None , skipna = True ):
452+
453+ mask = isnull (values )
447454 if not _is_floating_dtype (values ):
448455 values = values .astype ('f8' )
449456
450- mask = isnull (values )
451457 count = _get_counts (mask , axis )
452458
453459 if skipna :
@@ -476,12 +482,13 @@ def nanskew(values, axis=None, skipna=True):
476482 return result
477483
478484
479- @disallow ('M8' )
485+ @disallow ('M8' , 'm8' )
480486def nankurt (values , axis = None , skipna = True ):
487+
488+ mask = isnull (values )
481489 if not _is_floating_dtype (values ):
482490 values = values .astype ('f8' )
483491
484- mask = isnull (values )
485492 count = _get_counts (mask , axis )
486493
487494 if skipna :
@@ -574,7 +581,7 @@ def _zero_out_fperr(arg):
574581 return 0 if np .abs (arg ) < 1e-14 else arg
575582
576583
577- @disallow ('M8' )
584+ @disallow ('M8' , 'm8' )
578585def nancorr (a , b , method = 'pearson' , min_periods = None ):
579586 """
580587 a, b: ndarrays
@@ -621,7 +628,7 @@ def _spearman(a, b):
621628 return _cor_methods [method ]
622629
623630
624- @disallow ('M8' )
631+ @disallow ('M8' , 'm8' )
625632def nancov (a , b , min_periods = None ):
626633 if len (a ) != len (b ):
627634 raise AssertionError ('Operands to nancov must have same size' )
0 commit comments