Copilot commented on code in PR #50465:
URL: https://github.com/apache/arrow/pull/50465#discussion_r3559277519
##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -1292,24 +1292,11 @@ struct ObjectWriterVisitor {
auto to_date_offset = [&](const MonthDayNanoIntervalType::MonthDayNanos&
interval,
PyObject** out) {
ARROW_DCHECK(internal::BorrowPandasDataOffsetType() != nullptr);
- // DateOffset objects do not add nanoseconds component to pd.Timestamp.
- // as of Pandas 1.3.3
- // (https://github.com/pandas-dev/pandas/issues/43892).
- // So convert microseconds and remainder to preserve data
- // but give users more expected results.
- int64_t microseconds = interval.nanoseconds / 1000;
- int64_t nanoseconds;
- if (interval.nanoseconds >= 0) {
- nanoseconds = interval.nanoseconds % 1000;
- } else {
- nanoseconds = -((-interval.nanoseconds) % 1000);
- }
PyDict_SetItemString(kwargs.obj(), "months",
PyLong_FromLong(interval.months));
PyDict_SetItemString(kwargs.obj(), "days",
PyLong_FromLong(interval.days));
- PyDict_SetItemString(kwargs.obj(), "microseconds",
- PyLong_FromLongLong(microseconds));
- PyDict_SetItemString(kwargs.obj(), "nanoseconds",
PyLong_FromLongLong(nanoseconds));
+ PyDict_SetItemString(kwargs.obj(), "nanoseconds",
+ PyLong_FromLongLong(interval.nanoseconds));
Review Comment:
The PyLong objects created by PyLong_FromLong / PyLong_FromLongLong are new
references; passing them directly into PyDict_SetItemString without a DECREF
(or an owning wrapper) leaks one reference per element. Wrap these temporaries
in OwnedRef (or DECREF after insertion) and check for PyErr after setting items.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]