Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #40412 to pyarrow-14.x #41222

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/pyarrow/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,8 @@ class PyStructConverter : public StructConverter<PyConverter, PyConverterTrait>
case KeyKind::BYTES:
return AppendDict(dict, bytes_field_names_.obj());
default:
RETURN_NOT_OK(InferKeyKind(PyDict_Items(dict)));
OwnedRef item_ref(PyDict_Items(dict));
RETURN_NOT_OK(InferKeyKind(item_ref.obj()));
if (key_kind_ == KeyKind::UNKNOWN) {
// was unable to infer the type which means that all keys are absent
return AppendEmpty();
Expand Down Expand Up @@ -1083,6 +1084,7 @@ class PyStructConverter : public StructConverter<PyConverter, PyConverterTrait>
Result<std::pair<PyObject*, PyObject*>> GetKeyValuePair(PyObject* seq, int index) {
PyObject* pair = PySequence_GetItem(seq, index);
RETURN_IF_PYERROR();
OwnedRef pair_ref(pair); // ensure reference count is decreased at scope end
if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2) {
return internal::InvalidType(pair, "was expecting tuple of (key, value) pair");
}
Expand Down
Loading