jorisvandenbossche commented on code in PR #14448:
URL: https://github.com/apache/arrow/pull/14448#discussion_r998406180


##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -1074,11 +1074,28 @@ struct ObjectWriterVisitor {
     auto ConvertTimezoneAware = [&](typename Type::c_type value, PyObject** 
out) {
       PyObject* naive_datetime;
       RETURN_NOT_OK(ConvertTimezoneNaive(value, &naive_datetime));
+
       // convert the timezone naive datetime object to timezone aware
-      *out = PyObject_CallMethod(tzinfo.obj(), "fromutc", "O", naive_datetime);
-      // the timezone naive object is no longer required
+      // first: replacing timezone with timezone.utc
+      PyObject* args = PyTuple_New(0);
+      PyObject* keywords = PyDict_New();
+      PyDict_SetItemString(keywords, "tzinfo", PyDateTime_TimeZone_UTC);
+      PyObject* naive_datetime_replace =
+          PyObject_GetAttrString(naive_datetime, "replace");
+      PyObject* datetime_utc = PyObject_Call(naive_datetime_replace, args, 
keywords);
+      // second: adjust the datetime to tzinfo timezone
+      PyObject* astimezone = PyObject_GetAttrString(datetime_utc, 
"astimezone");
+      *out = PyObject_CallOneArg(astimezone, tzinfo.obj());
+
+      // arguments for replace method and the timezone naive object are no 
longer required
+      Py_DECREF(args);

Review Comment:
   You could also use `OwnedRef` to avoid this list of DECREFs, that might give 
a bit cleaner code?



##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -1074,11 +1074,28 @@ struct ObjectWriterVisitor {
     auto ConvertTimezoneAware = [&](typename Type::c_type value, PyObject** 
out) {
       PyObject* naive_datetime;
       RETURN_NOT_OK(ConvertTimezoneNaive(value, &naive_datetime));
+
       // convert the timezone naive datetime object to timezone aware

Review Comment:
   Can you add here in a comment the python code that this is mimicking? 



-- 
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]

Reply via email to