1
- from pandas import compat
2
1
import sys
3
2
import itertools
4
3
import functools
5
4
6
5
import numpy as np
7
6
8
- from pandas .core .common import isnull , notnull , _values_from_object , is_float
9
- import pandas .core .common as com
10
- import pandas .lib as lib
11
- import pandas .algos as algos
12
- import pandas .hashtable as _hash
13
- import pandas .tslib as tslib
14
-
15
- from pandas .compat import builtins
16
-
17
-
18
7
try :
19
8
import bottleneck as bn
20
9
_USE_BOTTLENECK = True
21
10
except ImportError : # pragma: no cover
22
11
_USE_BOTTLENECK = False
23
12
13
+ import pandas .core .common as com
14
+ import pandas .hashtable as _hash
15
+ from pandas import compat , lib , algos , tslib
16
+ from pandas .compat import builtins
17
+ from pandas .core .common import isnull , notnull , _values_from_object , is_float
18
+
24
19
25
20
class disallow (object ):
26
21
@@ -75,7 +70,8 @@ def f(values, axis=None, skipna=True, **kwds):
75
70
result .fill (0 )
76
71
return result
77
72
78
- if _USE_BOTTLENECK and skipna and _bn_ok_dtype (values .dtype , bn_name ):
73
+ if _USE_BOTTLENECK and skipna and _bn_ok_dtype (values .dtype ,
74
+ bn_name ):
79
75
result = bn_func (values , axis = axis , ** kwds )
80
76
81
77
# prefer to treat inf/-inf as NA, but must compute the func
@@ -94,7 +90,8 @@ def f(values, axis=None, skipna=True, **kwds):
94
90
95
91
def _bn_ok_dtype (dt , name ):
96
92
# Bottleneck chokes on datetime64
97
- if dt != np .object_ and not issubclass (dt .type , (np .datetime64 , np .timedelta64 )):
93
+ if dt != np .object_ and not issubclass (dt .type , (np .datetime64 ,
94
+ np .timedelta64 )):
98
95
99
96
# bottleneck does not properly upcast during the sum
100
97
# so can overflow
@@ -179,8 +176,9 @@ def _get_values(values, skipna, fill_value=None, fill_value_typ=None,
179
176
180
177
# return a platform independent precision dtype
181
178
dtype_max = dtype
182
- if dtype .kind == 'i' and not issubclass (
183
- dtype .type , (np .bool , np .datetime64 , np .timedelta64 )):
179
+ if dtype .kind == 'i' and not issubclass (dtype .type , (np .bool ,
180
+ np .datetime64 ,
181
+ np .timedelta64 )):
184
182
dtype_max = np .int64
185
183
elif dtype .kind in ['b' ] or issubclass (dtype .type , np .bool ):
186
184
dtype_max = np .int64
@@ -251,7 +249,7 @@ def nanall(values, axis=None, skipna=True):
251
249
@bottleneck_switch (zero_value = 0 )
252
250
def nansum (values , axis = None , skipna = True ):
253
251
values , mask , dtype , dtype_max = _get_values (values , skipna , 0 )
254
- the_sum = values .sum (axis ,dtype = dtype_max )
252
+ the_sum = values .sum (axis , dtype = dtype_max )
255
253
the_sum = _maybe_null_out (the_sum , axis , mask )
256
254
257
255
return _wrap_results (the_sum , dtype )
@@ -365,7 +363,8 @@ def nansem(values, axis=None, skipna=True, ddof=1):
365
363
366
364
@bottleneck_switch ()
367
365
def nanmin (values , axis = None , skipna = True ):
368
- values , mask , dtype , dtype_max = _get_values (values , skipna , fill_value_typ = '+inf' )
366
+ values , mask , dtype , dtype_max = _get_values (values , skipna ,
367
+ fill_value_typ = '+inf' )
369
368
370
369
# numpy 1.6.1 workaround in Python 3.x
371
370
if (values .dtype == np .object_ and compat .PY3 ):
@@ -381,7 +380,7 @@ def nanmin(values, axis=None, skipna=True):
381
380
if ((axis is not None and values .shape [axis ] == 0 )
382
381
or values .size == 0 ):
383
382
try :
384
- result = com .ensure_float (values .sum (axis ,dtype = dtype_max ))
383
+ result = com .ensure_float (values .sum (axis , dtype = dtype_max ))
385
384
result .fill (np .nan )
386
385
except :
387
386
result = np .nan
@@ -394,7 +393,8 @@ def nanmin(values, axis=None, skipna=True):
394
393
395
394
@bottleneck_switch ()
396
395
def nanmax (values , axis = None , skipna = True ):
397
- values , mask , dtype , dtype_max = _get_values (values , skipna , fill_value_typ = '-inf' )
396
+ values , mask , dtype , dtype_max = _get_values (values , skipna ,
397
+ fill_value_typ = '-inf' )
398
398
399
399
# numpy 1.6.1 workaround in Python 3.x
400
400
if (values .dtype == np .object_ and compat .PY3 ):
@@ -427,7 +427,7 @@ def nanargmax(values, axis=None, skipna=True):
427
427
Returns -1 in the NA case
428
428
"""
429
429
values , mask , dtype , _ = _get_values (values , skipna , fill_value_typ = '-inf' ,
430
- isfinite = True )
430
+ isfinite = True )
431
431
result = values .argmax (axis )
432
432
result = _maybe_arg_null_out (result , axis , mask , skipna )
433
433
return result
@@ -438,7 +438,7 @@ def nanargmin(values, axis=None, skipna=True):
438
438
Returns -1 in the NA case
439
439
"""
440
440
values , mask , dtype , _ = _get_values (values , skipna , fill_value_typ = '+inf' ,
441
- isfinite = True )
441
+ isfinite = True )
442
442
result = values .argmin (axis )
443
443
result = _maybe_arg_null_out (result , axis , mask , skipna )
444
444
return result
0 commit comments