Skip to content

Commit 9930a55

Browse files
committed
reshuffle code, so it becomes more obvious which functions are defined for which c_types
1 parent 4efdc67 commit 9930a55

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

pandas/_libs/hashtable_class_helper.pxi.in

+27-25
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,53 @@ cdef kh{{name}}_t to_kh{{name}}_t({{name}}_t val) nogil:
1919
res.imag = val.imag
2020
return res
2121

22+
2223
cdef {{name}}_t to_{{name}}(kh{{name}}_t val) nogil:
2324
cdef {{name}}_t res
2425
res.real = val.real
2526
res.imag = val.imag
2627
return res
2728

28-
cdef bint is_nan_kh{{name}}_t(kh{{name}}_t val) nogil:
29-
return val.real != val.real or val.imag != val.imag
30-
{{endfor}}
31-
32-
33-
{{py:
34-
35-
# name
36-
float_types = ['float64_t',
37-
'float32_t']
38-
}}
39-
40-
{{for c_type in float_types}}
41-
42-
cdef bint is_nan_{{c_type}}({{c_type}} val) nogil:
43-
return val != val
4429
{{endfor}}
4530

4631

4732
{{py:
4833

4934

5035
# name
51-
int_types = ['int64_t',
52-
'int32_t',
53-
'int16_t',
54-
'int8_t',
55-
'uint64_t',
56-
'uint32_t',
57-
'uint16_t',
58-
'uint8_t']
36+
c_types = ['khcomplex128_t',
37+
'khcomplex64_t',
38+
'float64_t',
39+
'float32_t',
40+
'int64_t',
41+
'int32_t',
42+
'int16_t',
43+
'int8_t',
44+
'uint64_t',
45+
'uint32_t',
46+
'uint16_t',
47+
'uint8_t']
5948
}}
6049

61-
{{for c_type in int_types}}
50+
{{for c_type in c_types}}
6251

6352
cdef bint is_nan_{{c_type}}({{c_type}} val) nogil:
53+
{{if c_type in {'khcomplex128_t', 'khcomplex64_t'} }}
54+
return val.real != val.real or val.imag != val.imag
55+
{{elif c_type in {'float64_t', 'float32_t'} }}
56+
return val != val
57+
{{else}}
6458
return False
59+
{{endif}}
60+
6561

62+
{{if c_type in {'khcomplex128_t', 'khcomplex64_t', 'float64_t', 'float32_t'} }}
63+
# are_equivalent_{{c_type}} is cimported via khash.pxd
64+
{{else}}
6665
cdef bint are_equivalent_{{c_type}}({{c_type}} val1, {{c_type}} val2) nogil:
6766
return val1 == val2
67+
{{endif}}
68+
6869
{{endfor}}
6970

7071

@@ -97,6 +98,7 @@ from pandas._libs.khash cimport (
9798
kh_put_{{name}},
9899
kh_resize_{{name}},
99100
)
101+
100102
{{endfor}}
101103

102104
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)