@@ -81,7 +81,7 @@ cdef class Reducer:
81
81
82
82
else :
83
83
84
- # we passed a series-like
84
+ # we passed a Series
85
85
typ = type (dummy)
86
86
index = dummy.index
87
87
dummy = dummy.values
@@ -99,7 +99,6 @@ cdef class Reducer:
99
99
ndarray arr, result, chunk
100
100
Py_ssize_t i
101
101
flatiter it
102
- bint has_labels
103
102
object res, name, labels
104
103
object cached_typ = None
105
104
@@ -108,42 +107,26 @@ cdef class Reducer:
108
107
dummy_buf = chunk.data
109
108
chunk.data = arr.data
110
109
labels = self .labels
111
- has_labels = labels is not None
112
- has_index = self .index is not None
113
110
114
111
result = np.empty(self .nresults, dtype = ' O' )
115
112
it = < flatiter> PyArray_IterNew(result)
116
113
117
114
try :
118
115
for i in range (self .nresults):
119
116
120
- if has_labels:
121
- name = labels[i]
122
- else :
123
- name = None
124
-
125
117
# create the cached type
126
118
# each time just reassign the data
127
119
if i == 0 :
128
120
129
121
if self .typ is not None :
130
-
131
- # recreate with the index if supplied
132
- if has_index:
133
-
134
- cached_typ = self .typ(
135
- chunk, index = self .index, name = name)
136
-
137
- else :
138
-
139
- # use the passsed typ, sans index
140
- cached_typ = self .typ(chunk, name = name)
122
+ # In this case, we also have self.index
123
+ name = labels[i]
124
+ cached_typ = self .typ(chunk, index = self .index, name = name)
141
125
142
126
# use the cached_typ if possible
143
127
if cached_typ is not None :
144
-
145
- if has_index:
146
- object .__setattr__ (cached_typ, ' index' , self .index)
128
+ # In this case, we also have non-None labels
129
+ name = labels[i]
147
130
148
131
object .__setattr__ (
149
132
cached_typ._data._block, ' values' , chunk)
@@ -607,18 +590,22 @@ cdef class BlockSlider:
607
590
arr.shape[1 ] = 0
608
591
609
592
610
- def compute_reduction (arr , f , axis = 0 , dummy = None , labels = None ):
593
+ def compute_reduction (arr: np. ndarray , f , axis: int = 0 , dummy = None , labels = None ):
611
594
"""
612
595
613
596
Parameters
614
597
-----------
615
- arr : NDFrame object
598
+ arr : np.ndarray
616
599
f : function
617
600
axis : integer axis
618
601
dummy : type of reduced output (series)
619
602
labels : Index or None
620
603
"""
621
604
605
+ # We either have both dummy and labels, or neither of them
606
+ if (labels is None ) ^ (dummy is None ):
607
+ raise ValueError (" Must pass either dummy and labels, or neither" )
608
+
622
609
if labels is not None :
623
610
# Caller is responsible for ensuring we don't have MultiIndex
624
611
assert labels.nlevels == 1
0 commit comments