@@ -1262,21 +1262,22 @@ def group_count_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
1262
1262
raise AssertionError("len(index) != len(labels)")
1263
1263
1264
1264
1265
- for i in range(N):
1266
- lab = labels[i]
1267
- if lab < 0:
1268
- continue
1269
-
1270
- counts[lab] += 1
1271
- for j in range(K):
1272
- val = values[i, j]
1273
-
1274
- # not nan
1275
- nobs[lab, j] += val == val and val != iNaT
1276
-
1277
- for i in range(ncounts):
1278
- for j in range(K):
1279
- out[i, j] = nobs[i, j]
1265
+ %(nogil)s
1266
+ %(tab)sfor i in range(N):
1267
+ %(tab)s lab = labels[i]
1268
+ %(tab)s if lab < 0:
1269
+ %(tab)s continue
1270
+
1271
+ %(tab)s counts[lab] += 1
1272
+ %(tab)s for j in range(K):
1273
+ %(tab)s val = values[i, j]
1274
+
1275
+ %(tab)s # not nan
1276
+ %(tab)s nobs[lab, j] += val == val and val != iNaT
1277
+
1278
+ %(tab)sfor i in range(ncounts):
1279
+ %(tab)s for j in range(K):
1280
+ %(tab)s out[i, j] = nobs[i, j]
1280
1281
"""
1281
1282
1282
1283
group_count_bin_template = """@cython.wraparound(False)
@@ -1297,20 +1298,21 @@ def group_count_bin_%(name)s(ndarray[%(dest_type2)s, ndim=2] out,
1297
1298
1298
1299
ngroups = len(bins) + (bins[len(bins) - 1] != N)
1299
1300
1300
- for i in range(N):
1301
- while b < ngroups - 1 and i >= bins[b]:
1302
- b += 1
1301
+ %(nogil)s
1302
+ %(tab)sfor i in range(N):
1303
+ %(tab)s while b < ngroups - 1 and i >= bins[b]:
1304
+ %(tab)s b += 1
1303
1305
1304
- counts[b] += 1
1305
- for j in range(K):
1306
- val = values[i, j]
1306
+ %(tab)s counts[b] += 1
1307
+ %(tab)s for j in range(K):
1308
+ %(tab)s val = values[i, j]
1307
1309
1308
- # not nan
1309
- nobs[b, j] += val == val and val != iNaT
1310
+ %(tab)s # not nan
1311
+ %(tab)s nobs[b, j] += val == val and val != iNaT
1310
1312
1311
- for i in range(ngroups):
1312
- for j in range(K):
1313
- out[i, j] = nobs[i, j]
1313
+ %(tab)sfor i in range(ngroups):
1314
+ %(tab)s for j in range(K):
1315
+ %(tab)s out[i, j] = nobs[i, j]
1314
1316
"""
1315
1317
1316
1318
# add passing bin edges, instead of labels
@@ -2312,19 +2314,19 @@ def put2d_%(name)s_%(dest_type)s(ndarray[%(c_type)s, ndim=2, cast=True] values,
2312
2314
def generate_put_template (template , use_ints = True , use_floats = True ,
2313
2315
use_objects = False , use_datelikes = False ):
2314
2316
floats_list = [
2315
- ('float64' , 'float64_t' , 'float64_t' , 'np.float64' ),
2316
- ('float32' , 'float32_t' , 'float32_t' , 'np.float32' ),
2317
+ ('float64' , 'float64_t' , 'float64_t' , 'np.float64' , True ),
2318
+ ('float32' , 'float32_t' , 'float32_t' , 'np.float32' , True ),
2317
2319
]
2318
2320
ints_list = [
2319
- ('int8' , 'int8_t' , 'float32_t' , 'np.float32' ),
2320
- ('int16' , 'int16_t' , 'float32_t' , 'np.float32' ),
2321
- ('int32' , 'int32_t' , 'float64_t' , 'np.float64' ),
2322
- ('int64' , 'int64_t' , 'float64_t' , 'np.float64' ),
2321
+ ('int8' , 'int8_t' , 'float32_t' , 'np.float32' , True ),
2322
+ ('int16' , 'int16_t' , 'float32_t' , 'np.float32' , True ),
2323
+ ('int32' , 'int32_t' , 'float64_t' , 'np.float64' , True ),
2324
+ ('int64' , 'int64_t' , 'float64_t' , 'np.float64' , True ),
2323
2325
]
2324
2326
date_like_list = [
2325
- ('int64' , 'int64_t' , 'float64_t' , 'np.float64' ),
2327
+ ('int64' , 'int64_t' , 'float64_t' , 'np.float64' , True ),
2326
2328
]
2327
- object_list = [('object' , 'object' , 'object' , 'np.object_' )]
2329
+ object_list = [('object' , 'object' , 'object' , 'np.object_' , False )]
2328
2330
function_list = []
2329
2331
if use_floats :
2330
2332
function_list .extend (floats_list )
@@ -2336,29 +2338,31 @@ def generate_put_template(template, use_ints=True, use_floats=True,
2336
2338
function_list .extend (date_like_list )
2337
2339
2338
2340
output = StringIO ()
2339
- for name , c_type , dest_type , dest_dtype in function_list :
2341
+ for name , c_type , dest_type , dest_dtype , nogil in function_list :
2340
2342
func = template % {'name' : name ,
2341
2343
'c_type' : c_type ,
2342
2344
'dest_type' : dest_type .replace ('_t' , '' ),
2343
2345
'dest_type2' : dest_type ,
2344
- 'dest_dtype' : dest_dtype }
2346
+ 'dest_dtype' : dest_dtype ,
2347
+ 'nogil' : 'with nogil:' if nogil else '' ,
2348
+ 'tab' : ' ' if nogil else '' }
2345
2349
output .write (func )
2346
2350
output .write ("\n " )
2347
2351
return output .getvalue ()
2348
2352
2349
2353
def generate_put_min_max_template (template , use_ints = True , use_floats = True ,
2350
2354
use_objects = False , use_datelikes = False ):
2351
2355
floats_list = [
2352
- ('float64' , 'float64_t' , 'NAN' , 'np.inf' ),
2353
- ('float32' , 'float32_t' , 'NAN' , 'np.inf' ),
2356
+ ('float64' , 'float64_t' , 'NAN' , 'np.inf' , True ),
2357
+ ('float32' , 'float32_t' , 'NAN' , 'np.inf' , True ),
2354
2358
]
2355
2359
ints_list = [
2356
- ('int64' , 'int64_t' , 'iNaT' , _int64_max ),
2360
+ ('int64' , 'int64_t' , 'iNaT' , _int64_max , True ),
2357
2361
]
2358
2362
date_like_list = [
2359
- ('int64' , 'int64_t' , 'iNaT' , _int64_max ),
2363
+ ('int64' , 'int64_t' , 'iNaT' , _int64_max , True ),
2360
2364
]
2361
- object_list = [('object' , 'object' , 'np.nan' , 'np.inf' )]
2365
+ object_list = [('object' , 'object' , 'np.nan' , 'np.inf' , False )]
2362
2366
function_list = []
2363
2367
if use_floats :
2364
2368
function_list .extend (floats_list )
@@ -2370,28 +2374,30 @@ def generate_put_min_max_template(template, use_ints=True, use_floats=True,
2370
2374
function_list .extend (date_like_list )
2371
2375
2372
2376
output = StringIO ()
2373
- for name , dest_type , nan_val , inf_val in function_list :
2377
+ for name , dest_type , nan_val , inf_val , nogil in function_list :
2374
2378
func = template % {'name' : name ,
2375
2379
'dest_type2' : dest_type ,
2376
2380
'nan_val' : nan_val ,
2377
- 'inf_val' : inf_val }
2381
+ 'inf_val' : inf_val ,
2382
+ 'nogil' : "with nogil:" if nogil else '' ,
2383
+ 'tab' : ' ' if nogil else '' }
2378
2384
output .write (func )
2379
2385
output .write ("\n " )
2380
2386
return output .getvalue ()
2381
2387
2382
2388
def generate_put_selection_template (template , use_ints = True , use_floats = True ,
2383
2389
use_objects = False , use_datelikes = False ):
2384
2390
floats_list = [
2385
- ('float64' , 'float64_t' , 'float64_t' , 'NAN' ),
2386
- ('float32' , 'float32_t' , 'float32_t' , 'NAN' ),
2391
+ ('float64' , 'float64_t' , 'float64_t' , 'NAN' , True ),
2392
+ ('float32' , 'float32_t' , 'float32_t' , 'NAN' , True ),
2387
2393
]
2388
2394
ints_list = [
2389
- ('int64' , 'int64_t' , 'int64_t' , 'iNaT' ),
2395
+ ('int64' , 'int64_t' , 'int64_t' , 'iNaT' , True ),
2390
2396
]
2391
2397
date_like_list = [
2392
- ('int64' , 'int64_t' , 'int64_t' , 'iNaT' ),
2398
+ ('int64' , 'int64_t' , 'int64_t' , 'iNaT' , True ),
2393
2399
]
2394
- object_list = [('object' , 'object' , 'object' , 'np.nan' )]
2400
+ object_list = [('object' , 'object' , 'object' , 'np.nan' , False )]
2395
2401
function_list = []
2396
2402
if use_floats :
2397
2403
function_list .extend (floats_list )
@@ -2403,11 +2409,13 @@ def generate_put_selection_template(template, use_ints=True, use_floats=True,
2403
2409
function_list .extend (date_like_list )
2404
2410
2405
2411
output = StringIO ()
2406
- for name , c_type , dest_type , nan_val in function_list :
2412
+ for name , c_type , dest_type , nan_val , nogil in function_list :
2407
2413
func = template % {'name' : name ,
2408
2414
'c_type' : c_type ,
2409
2415
'dest_type2' : dest_type ,
2410
- 'nan_val' : nan_val }
2416
+ 'nan_val' : nan_val ,
2417
+ 'nogil' : "with nogil:" if nogil else "" ,
2418
+ 'tab' : ' ' if nogil else '' }
2411
2419
output .write (func )
2412
2420
output .write ("\n " )
2413
2421
return output .getvalue ()
0 commit comments