Skip to content

Commit a469656

Browse files
mpagejorisvandenbossche
authored andcommitted
Use PyMapping_Values() to retrieve the frame's locals
`PyFrame_GetLocals()` returns a proxy object in CPython 3.13+. Calling `PyDict_Next()` on the resulting object will not work because it is not a dictionary. Use `PyMapping_Values()` instead.
1 parent 4b1338c commit a469656

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pandas/_libs/src/frame_utils.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@ int is_local_in_caller_frame_impl(PyObject *object) {
3030
}
3131

3232
int result = 0;
33-
PyObject *key, *value;
3433
Py_ssize_t pos = 0;
35-
while (PyDict_Next(locals_dict, &pos, &key, &value)) {
36-
if (object == value) {
34+
PyObject *values = PyMapping_Values(locals_dict);
35+
if (values == NULL) {
36+
Py_DECREF(locals_dict);
37+
Py_DECREF(caller_frame);
38+
return 0;
39+
}
40+
Py_ssize_t num_values = PyList_Size(values);
41+
for (Py_ssize_t i = 0; i < num_values; i++) {
42+
if (PyList_GetItem(values, i) == object) {
3743
result = 1;
3844
break;
3945
}
4046
}
4147

48+
Py_DECREF(values);
4249
Py_DECREF(locals_dict);
4350
Py_DECREF(caller_frame);
4451
return result;

0 commit comments

Comments
 (0)