Skip to content

Commit 4411a29

Browse files
stephenwliny-p
authored and
y-p
committed
CLN: cleanup arguments in generate_code.py
1 parent 4d3e34e commit 4411a29

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

pandas/src/generate_code.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
take_1d_template = """@cython.wraparound(False)
5757
def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s] values,
5858
ndarray[int64_t] indexer,
59-
out, fill_value=np.nan):
59+
ndarray[%(c_type_out)s] out,
60+
fill_value=np.nan):
6061
cdef:
6162
Py_ssize_t i, n, idx
62-
ndarray[%(c_type_out)s] outbuf = out
6363
%(c_type_out)s fv
6464
6565
n = len(indexer)
@@ -68,20 +68,20 @@ def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s] values,
6868
for i from 0 <= i < n:
6969
idx = indexer[i]
7070
if idx == -1:
71-
outbuf[i] = fv
71+
out[i] = fv
7272
else:
73-
outbuf[i] = %(preval)svalues[idx]%(postval)s
73+
out[i] = %(preval)svalues[idx]%(postval)s
7474
7575
"""
7676

7777
take_2d_axis0_template = """@cython.wraparound(False)
7878
@cython.boundscheck(False)
7979
def take_2d_axis0_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
8080
ndarray[int64_t] indexer,
81-
out, fill_value=np.nan):
81+
ndarray[%(c_type_out)s, ndim=2] out,
82+
fill_value=np.nan):
8283
cdef:
8384
Py_ssize_t i, j, k, n, idx
84-
ndarray[%(c_type_out)s, ndim=2] outbuf = out
8585
%(c_type_out)s fv
8686
8787
n = len(indexer)
@@ -98,37 +98,40 @@ def take_2d_axis0_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
9898
idx = indexer[i]
9999
if idx == -1:
100100
for j from 0 <= j < k:
101-
outbuf[i, j] = fv
101+
out[i, j] = fv
102102
else:
103103
v = &values[idx, 0]
104-
o = &outbuf[i, 0]
104+
o = &out[i, 0]
105105
memmove(o, v, <size_t>(sizeof(%(c_type_out)s) * k))
106106
return
107107
108108
for i from 0 <= i < n:
109109
idx = indexer[i]
110110
if idx == -1:
111111
for j from 0 <= j < k:
112-
outbuf[i, j] = fv
112+
out[i, j] = fv
113113
else:
114114
for j from 0 <= j < k:
115-
outbuf[i, j] = %(preval)svalues[idx, j]%(postval)s
115+
out[i, j] = %(preval)svalues[idx, j]%(postval)s
116116
117117
"""
118118

119119
take_2d_axis1_template = """@cython.wraparound(False)
120120
@cython.boundscheck(False)
121121
def take_2d_axis1_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
122122
ndarray[int64_t] indexer,
123-
out, fill_value=np.nan):
123+
ndarray[%(c_type_out)s, ndim=2] out,
124+
fill_value=np.nan):
124125
cdef:
125126
Py_ssize_t i, j, k, n, idx
126-
ndarray[%(c_type_out)s, ndim=2] outbuf = out
127127
%(c_type_out)s fv
128128
129129
n = len(values)
130130
k = len(indexer)
131-
131+
132+
if n == 0 or k == 0:
133+
return
134+
132135
fv = fill_value
133136
134137
IF %(can_copy)s:
@@ -140,34 +143,34 @@ def take_2d_axis1_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
140143
idx = indexer[j]
141144
if idx == -1:
142145
for i from 0 <= i < n:
143-
outbuf[i, j] = fv
146+
out[i, j] = fv
144147
else:
145148
v = &values[0, idx]
146-
o = &outbuf[0, j]
149+
o = &out[0, j]
147150
memmove(o, v, <size_t>(sizeof(%(c_type_out)s) * n))
148151
return
149152
150153
for j from 0 <= j < k:
151154
idx = indexer[j]
152155
if idx == -1:
153156
for i from 0 <= i < n:
154-
outbuf[i, j] = fv
157+
out[i, j] = fv
155158
else:
156159
for i from 0 <= i < n:
157-
outbuf[i, j] = %(preval)svalues[i, idx]%(postval)s
160+
out[i, j] = %(preval)svalues[i, idx]%(postval)s
158161
159162
"""
160163

161164
take_2d_multi_template = """@cython.wraparound(False)
162165
@cython.boundscheck(False)
163166
def take_2d_multi_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
164167
indexer,
165-
out, fill_value=np.nan):
168+
ndarray[%(c_type_out)s, ndim=2] out,
169+
fill_value=np.nan):
166170
cdef:
167171
Py_ssize_t i, j, k, n, idx
168172
ndarray[int64_t] idx0 = indexer[0]
169173
ndarray[int64_t] idx1 = indexer[1]
170-
ndarray[%(c_type_out)s, ndim=2] outbuf = out
171174
%(c_type_out)s fv
172175
173176
n = len(idx0)
@@ -178,13 +181,13 @@ def take_2d_multi_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
178181
idx = idx0[i]
179182
if idx == -1:
180183
for j from 0 <= j < k:
181-
outbuf[i, j] = fv
184+
out[i, j] = fv
182185
else:
183186
for j from 0 <= j < k:
184187
if idx1[j] == -1:
185-
outbuf[i, j] = fv
188+
out[i, j] = fv
186189
else:
187-
outbuf[i, j] = %(preval)svalues[idx, idx1[j]]%(postval)s
190+
out[i, j] = %(preval)svalues[idx, idx1[j]]%(postval)s
188191
189192
"""
190193

@@ -2169,7 +2172,7 @@ def generate_put_template(template, use_ints = True, use_floats = True):
21692172

21702173
output = StringIO()
21712174
for name, c_type, dest_type, dest_dtype in function_list:
2172-
func = template % {'name' : name,
2175+
func = template % {'name' : name,
21732176
'c_type' : c_type,
21742177
'dest_type' : dest_type.replace('_t', ''),
21752178
'dest_type2' : dest_type,
@@ -2203,7 +2206,7 @@ def generate_take_template(template, exclude=None):
22032206
]
22042207

22052208
output = StringIO()
2206-
for (name, dest, c_type_in, c_type_out,
2209+
for (name, dest, c_type_in, c_type_out,
22072210
preval, postval, can_copy) in function_list:
22082211
if exclude is not None and name in exclude:
22092212
continue

0 commit comments

Comments
 (0)