@@ -39,20 +39,23 @@ cdef build_count_table_{{dtype}}({{dtype}}_t[:] values,
39
39
int ret = 0
40
40
41
41
{{if dtype == 'object'}}
42
+ print('object way')
42
43
kh_resize_{{ttype}}(table, n // 10)
43
44
44
45
for i in range(n):
45
46
val = values[i]
46
47
47
48
if not checknull(val) or not dropna:
48
49
k = kh_get_{{ttype}}(table, <PyObject*> val)
50
+ print(k, val, table.n_buckets)
49
51
if k != table.n_buckets:
50
52
table.vals[k] += 1
51
53
else:
52
54
k = kh_put_{{ttype}}(table, <PyObject*> val, &ret)
53
55
table.vals[k] = 1
54
56
{{else}}
55
57
with nogil:
58
+ #print('non-object way')
56
59
kh_resize_{{ttype}}(table, n)
57
60
58
61
for i in range(n):
@@ -288,25 +291,25 @@ def ismember_{{dtype}}({{scalar}}[:] arr, {{scalar}}[:] values, bint hasnans=0):
288
291
{{py:
289
292
290
293
# dtype, ctype, table_type, npy_dtype
291
- dtypes = [('int64', 'int64_t', 'int64', 'int64'),
294
+ dtypes = [('float64', 'float64_t', 'float64', 'float64'),
295
+ ('int64', 'int64_t', 'int64', 'int64'),
292
296
('uint64', 'uint64_t', 'uint64', 'uint64'),
293
297
('object', 'object', 'pymap', 'object_')]
294
298
}}
295
299
296
300
{{for dtype, ctype, table_type, npy_dtype in dtypes}}
297
301
298
-
299
302
@cython.wraparound(False)
300
303
@cython.boundscheck(False)
301
304
302
305
{{if dtype == 'object'}}
303
306
304
307
305
- def mode_{{dtype}}(ndarray[{{ctype}}] values):
308
+ def mode_{{dtype}}(ndarray[{{ctype}}] values, bint dropna ):
306
309
{{else}}
307
310
308
311
309
- def mode_{{dtype}}({{ctype}}[:] values):
312
+ def mode_{{dtype}}({{ctype}}[:] values, bint dropna ):
310
313
{{endif}}
311
314
cdef:
312
315
int count, max_count = 1
@@ -317,9 +320,9 @@ def mode_{{dtype}}({{ctype}}[:] values):
317
320
318
321
table = kh_init_{{table_type}}()
319
322
{{if dtype == 'object'}}
320
- build_count_table_{{dtype}}(values, table, 1 )
323
+ build_count_table_{{dtype}}(values, table, dropna )
321
324
{{else}}
322
- build_count_table_{{dtype}}(values, table, 0 )
325
+ build_count_table_{{dtype}}(values, table, dropna )
323
326
{{endif}}
324
327
325
328
modes = np.empty(table.n_buckets, dtype=np.{{npy_dtype}})
@@ -329,7 +332,6 @@ def mode_{{dtype}}({{ctype}}[:] values):
329
332
for k in range(table.n_buckets):
330
333
if kh_exist_{{table_type}}(table, k):
331
334
count = table.vals[k]
332
-
333
335
if count == max_count:
334
336
j += 1
335
337
elif count > max_count:
@@ -342,6 +344,7 @@ def mode_{{dtype}}({{ctype}}[:] values):
342
344
{{else}}
343
345
for k in range(table.n_buckets):
344
346
if kh_exist_{{table_type}}(table, k):
347
+ print(<object> table.keys[k], table.vals[k])
345
348
count = table.vals[k]
346
349
347
350
if count == max_count:
0 commit comments