10
10
_USE_BOTTLENECK = False
11
11
12
12
def nansum (values , axis = None , skipna = True , copy = True ):
13
- if values .dtype == np .object_ :
14
- the_sum = values .sum (axis )
15
- else :
16
- mask = isnull (values )
13
+ mask = isnull (values )
17
14
18
- if skipna and not issubclass (values .dtype .type , np .integer ):
19
- if copy :
20
- values = values .copy ()
21
- np .putmask (values , mask , 0 )
15
+ if skipna and not issubclass (values .dtype .type , np .integer ):
16
+ if copy :
17
+ values = values .copy ()
18
+ np .putmask (values , mask , 0 )
22
19
23
- the_sum = values .sum (axis )
24
- the_sum = _maybe_null_out (the_sum , axis , mask )
20
+ the_sum = values .sum (axis )
21
+ the_sum = _maybe_null_out (the_sum , axis , mask )
25
22
26
23
return the_sum
27
24
28
25
def nanmean (values , axis = None , skipna = True , copy = True ):
29
- if values .dtype == np .object_ :
30
- the_mean = values .sum (axis ) / float (values .shape [axis ])
31
- else :
32
- mask = isnull (values )
33
-
34
- if skipna and not issubclass (values .dtype .type , np .integer ):
35
- if copy :
36
- values = values .copy ()
37
- np .putmask (values , mask , 0 )
26
+ mask = isnull (values )
38
27
39
- the_sum = values .sum (axis )
40
- count = _get_counts (mask , axis )
28
+ if skipna and not issubclass (values .dtype .type , np .integer ):
29
+ if copy :
30
+ values = values .copy ()
31
+ np .putmask (values , mask , 0 )
41
32
42
- if axis is not None :
43
- the_mean = the_sum / count
44
- ct_mask = count == 0
45
- if ct_mask .any ():
46
- the_mean [ct_mask ] = np .nan
47
- else :
48
- the_mean = the_sum / count if count > 0 else np .nan
33
+ the_sum = values .sum (axis )
34
+ count = _get_counts (mask , axis )
49
35
36
+ if axis is not None :
37
+ the_mean = the_sum / count
38
+ ct_mask = count == 0
39
+ if ct_mask .any ():
40
+ the_mean [ct_mask ] = np .nan
41
+ else :
42
+ the_mean = the_sum / count if count > 0 else np .nan
50
43
return the_mean
51
44
52
45
def nanmedian (values , axis = None , skipna = True , copy = True ):
@@ -121,7 +114,8 @@ def nanmin(values, axis=None, skipna=True, copy=True):
121
114
# numpy 1.6.1 workaround in Python 3.x
122
115
if values .dtype == np .object_ : # pragma: no cover
123
116
import __builtin__
124
- result = np .apply_along_axis (__builtin__ .min , axis , values )
117
+ apply_ax = axis if axis is not None else 0
118
+ result = np .apply_along_axis (__builtin__ .min , apply_ax , values )
125
119
else :
126
120
result = values .min (axis )
127
121
@@ -136,7 +130,8 @@ def nanmax(values, axis=None, skipna=True, copy=True):
136
130
# numpy 1.6.1 workaround in Python 3.x
137
131
if values .dtype == np .object_ : # pragma: no cover
138
132
import __builtin__
139
- result = np .apply_along_axis (__builtin__ .max , axis , values )
133
+ apply_ax = axis if axis is not None else 0
134
+ result = np .apply_along_axis (__builtin__ .max , apply_ax , values )
140
135
else :
141
136
result = values .max (axis )
142
137
return _maybe_null_out (result , axis , mask )
0 commit comments