Skip to content

Commit

Permalink
Revert apache#15210
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Newton committed Apr 30, 2024
1 parent 6a28035 commit c7da475
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions python/pyarrow/src/arrow/python/arrow_to_pandas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,11 @@ enable_if_list_like<T, Status> ConvertListsLike(PandasOptions options,
ArrayVector value_arrays;
for (int c = 0; c < data.num_chunks(); c++) {
const auto& arr = checked_cast<const ListArrayT&>(*data.chunk(c));
// values() does not account for offsets, so we need to slice into it.
// We can't use Flatten(), because it removes the values behind a null list
// value, and that makes the offsets into original list values and our
// flattened_values array different.
std::shared_ptr<Array> flattened_values = arr.values()->Slice(
arr.value_offset(0), arr.value_offset(arr.length()) - arr.value_offset(0));
if (arr.value_type()->id() == Type::EXTENSION) {
const auto& arr_ext = checked_cast<const ExtensionArray&>(*flattened_values);
const auto& arr_ext = checked_cast<const ExtensionArray&>(*arr.values());
value_arrays.emplace_back(arr_ext.storage());
} else {
value_arrays.emplace_back(flattened_values);
value_arrays.emplace_back(arr.values());
}
}

Expand Down Expand Up @@ -803,12 +797,8 @@ enable_if_list_like<T, Status> ConvertListsLike(PandasOptions options,
Py_INCREF(Py_None);
*out_values = Py_None;
} else {
// Need to subtract value_offset(0) since the original chunk might be a slice
// into another array.
OwnedRef start(PyLong_FromLongLong(arr.value_offset(i) + chunk_offset -
arr.value_offset(0)));
OwnedRef end(PyLong_FromLongLong(arr.value_offset(i + 1) + chunk_offset -
arr.value_offset(0)));
OwnedRef start(PyLong_FromLongLong(arr.value_offset(i) + chunk_offset));
OwnedRef end(PyLong_FromLongLong(arr.value_offset(i + 1) + chunk_offset));
OwnedRef slice(PySlice_New(start.obj(), end.obj(), nullptr));

if (ARROW_PREDICT_FALSE(slice.obj() == nullptr)) {
Expand All @@ -826,7 +816,7 @@ enable_if_list_like<T, Status> ConvertListsLike(PandasOptions options,
}
RETURN_IF_PYERROR();

chunk_offset += arr.value_offset(arr.length()) - arr.value_offset(0);
chunk_offset += arr.values()->length();
}

return Status::OK();
Expand Down Expand Up @@ -1252,8 +1242,7 @@ struct ObjectWriterVisitor {
OwnedRef keywords(PyDict_New());
PyDict_SetItemString(keywords.obj(), "tzinfo", PyDateTime_TimeZone_UTC);
OwnedRef naive_datetime_replace(PyObject_GetAttrString(naive_datetime, "replace"));
OwnedRef datetime_utc(
PyObject_Call(naive_datetime_replace.obj(), args.obj(), keywords.obj()));
OwnedRef datetime_utc(PyObject_Call(naive_datetime_replace.obj(), args.obj(), keywords.obj()));
// second step: adjust the datetime to tzinfo timezone (astimezone method)
*out = PyObject_CallMethod(datetime_utc.obj(), "astimezone", "O", tzinfo.obj());

Expand Down

0 comments on commit c7da475

Please sign in to comment.