@@ -77,9 +77,9 @@ cdef build_count_table_{{dtype}}(const {{dtype}}_t[:] values,
77
77
@cython.wraparound(False)
78
78
@cython.boundscheck(False)
79
79
{{if dtype == 'object'}}
80
- cpdef stable_value_count_ {{dtype}}(ndarray[{{dtype}}] values, bint dropna):
80
+ cpdef value_count_ {{dtype}}(ndarray[{{dtype}}] values, bint dropna, navalue=np.NaN ):
81
81
{{else}}
82
- cpdef stable_value_count_ {{dtype}}(const {{dtype}}_t[:] values, bint dropna):
82
+ cpdef value_count_ {{dtype}}(const {{dtype}}_t[:] values, bint dropna):
83
83
{{endif}}
84
84
cdef:
85
85
Py_ssize_t i = 0
@@ -90,6 +90,7 @@ cpdef stable_value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):
90
90
91
91
# Don't use Py_ssize_t, since table.n_buckets is unsigned
92
92
khiter_t k
93
+ bint is_null
93
94
94
95
{{c_type}} val
95
96
@@ -108,7 +109,10 @@ cpdef stable_value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):
108
109
109
110
for i in range(n):
110
111
val = values[i]
111
- if not checknull(val) or not dropna:
112
+ is_null = checknull(val)
113
+ if is_null:
114
+ val = navalue
115
+ if not is_null or not dropna:
112
116
k = kh_get_{{ttype}}(table, <PyObject*>val)
113
117
if k != table.n_buckets:
114
118
unique_key_index = table.vals[k]
@@ -143,15 +147,6 @@ cpdef stable_value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):
143
147
return result_keys.to_array(), result_counts.to_array()
144
148
145
149
146
- {{if dtype == 'object'}}
147
- cpdef value_count_{{dtype}}(ndarray[{{dtype}}] values, bint dropna):
148
- return stable_value_count_{{dtype}}(values, 1)
149
- {{else}}
150
- cpdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):
151
- return stable_value_count_{{dtype}}(values, dropna)
152
- {{endif}}
153
-
154
-
155
150
@cython.wraparound(False)
156
151
@cython.boundscheck(False)
157
152
{{if dtype == 'object'}}
0 commit comments