Skip to content

Commit cf238cd

Browse files
msimaceksteve-s
authored andcommitted
Update pandas patch to avoid direct access to PyComplexObject.cval
1 parent c6e2bf8 commit cf238cd

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

graalpython/lib-graalpython/modules/autopatch_capi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def consume_whitespace_forward(idx):
154154
# avoid direct access:
155155
r'\W(ob_type)\W': (replace_field_access, 'Py_TYPE(%receiver)'),
156156
r'\W(ob_refcnt)\W': (replace_field_access, 'Py_REFCNT(%receiver)'),
157-
r'\W(ob_item)\W': (replace_field_access, 'PySequence_Fast_ITEMS(%receiver)'),
157+
r'\W(ob_item)\W': (replace_field_access, 'PySequence_Fast_ITEMS((PyObject*)%receiver)'),
158158
r'^\s*()(std::)?free\((const_cast<char \*>)?\(?\w+->m_ml->ml_doc\)?\);': (simple_replace, '//'),
159159
r'\W(m_ml\s*->\s*ml_doc)\W': (replace_field_access, 'PyObject_GetDoc((PyObject*)(%receiver))', 'PyObject_SetDoc((PyObject*)(%receiver), %value)'),
160160
# already defined by GraalPy:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[[rules]]
22
version = '== 1.4.3'
33
patch = 'pandas-1.4.3.patch'
4+
dist-type = 'sdist'
45

56
[[rules]]
67
# pin to 1.5.2
78
install-priority = 10
89
version = '== 1.5.2'
910
patch = 'pandas-1.5.2.patch'
11+
dist-type = 'sdist'

graalpython/lib-graalpython/patches/pandas/pandas-1.5.2.patch

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
diff --git a/pandas/_libs/src/klib/khash_python.h b/pandas/_libs/src/klib/khash_python.h
2+
index 5ae3c19..b9c6784 100644
3+
--- a/pandas/_libs/src/klib/khash_python.h
4+
+++ b/pandas/_libs/src/klib/khash_python.h
5+
@@ -178,28 +178,30 @@ int PANDAS_INLINE floatobject_cmp(PyFloatObject* a, PyFloatObject* b){
6+
// PyObject_RichCompareBool for complexobjects has a different behavior
7+
// needs to be replaced
8+
int PANDAS_INLINE complexobject_cmp(PyComplexObject* a, PyComplexObject* b){
9+
+ Py_complex a_cval = PyComplex_AsCComplex((PyObject*)a);
10+
+ Py_complex b_cval = PyComplex_AsCComplex((PyObject*)b);
11+
return (
12+
- Py_IS_NAN(a->cval.real) &&
13+
- Py_IS_NAN(b->cval.real) &&
14+
- Py_IS_NAN(a->cval.imag) &&
15+
- Py_IS_NAN(b->cval.imag)
16+
+ Py_IS_NAN(a_cval.real) &&
17+
+ Py_IS_NAN(b_cval.real) &&
18+
+ Py_IS_NAN(a_cval.imag) &&
19+
+ Py_IS_NAN(b_cval.imag)
20+
)
21+
||
22+
(
23+
- Py_IS_NAN(a->cval.real) &&
24+
- Py_IS_NAN(b->cval.real) &&
25+
- a->cval.imag == b->cval.imag
26+
+ Py_IS_NAN(a_cval.real) &&
27+
+ Py_IS_NAN(b_cval.real) &&
28+
+ a_cval.imag == b_cval.imag
29+
)
30+
||
31+
(
32+
- a->cval.real == b->cval.real &&
33+
- Py_IS_NAN(a->cval.imag) &&
34+
- Py_IS_NAN(b->cval.imag)
35+
+ a_cval.real == b_cval.real &&
36+
+ Py_IS_NAN(a_cval.imag) &&
37+
+ Py_IS_NAN(b_cval.imag)
38+
)
39+
||
40+
(
41+
- a->cval.real == b->cval.real &&
42+
- a->cval.imag == b->cval.imag
43+
+ a_cval.real == b_cval.real &&
44+
+ a_cval.imag == b_cval.imag
45+
);
46+
}
47+
48+
@@ -276,8 +278,9 @@ Py_hash_t PANDAS_INLINE floatobject_hash(PyFloatObject* key) {
49+
50+
// replaces _Py_HashDouble with _Pandas_HashDouble
51+
Py_hash_t PANDAS_INLINE complexobject_hash(PyComplexObject* key) {
52+
- Py_uhash_t realhash = (Py_uhash_t)_Pandas_HashDouble(key->cval.real);
53+
- Py_uhash_t imaghash = (Py_uhash_t)_Pandas_HashDouble(key->cval.imag);
54+
+ Py_complex cval = PyComplex_AsCComplex((PyObject*)key);
55+
+ Py_uhash_t realhash = (Py_uhash_t)_Pandas_HashDouble(cval.real);
56+
+ Py_uhash_t imaghash = (Py_uhash_t)_Pandas_HashDouble(cval.imag);
57+
if (realhash == (Py_uhash_t)-1 || imaghash == (Py_uhash_t)-1) {
58+
return -1;
59+
}
160
diff --git a/pandas/io/common.py b/pandas/io/common.py
261
index f31de63..1858912 100644
362
--- a/pandas/io/common.py

0 commit comments

Comments
 (0)