diff --git a/cpp/src/arrow/python/datetime.cc b/cpp/src/arrow/python/datetime.cc index 8df2012d3a0..4b18918cbcf 100644 --- a/cpp/src/arrow/python/datetime.cc +++ b/cpp/src/arrow/python/datetime.cc @@ -415,6 +415,16 @@ Result TzinfoToString(PyObject* tzinfo) { // HH:MM offset string representation if (PyObject_IsInstance(tzinfo, class_timezone.obj()) || PyObject_IsInstance(tzinfo, class_fixedoffset.obj())) { + // still recognize datetime.timezone.utc as UTC (instead of +00:00) + OwnedRef tzname_object(PyObject_CallMethod(tzinfo, "tzname", "O", Py_None)); + RETURN_IF_PYERROR(); + if (PyUnicode_Check(tzname_object.obj())) { + std::string result; + RETURN_NOT_OK(internal::PyUnicode_AsStdString(tzname_object.obj(), &result)); + if (result == "UTC") { + return result; + } + } return PyTZInfo_utcoffset_hhmm(tzinfo); } diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index 9ac2f01686f..4de5ffabfad 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -263,7 +263,7 @@ def test_is_primitive(): # name from the tzinfo.zone attribute (pytz.timezone('Etc/GMT-9'), 'Etc/GMT-9'), (pytz.FixedOffset(180), '+03:00'), - (datetime.timezone.utc, '+00:00'), + (datetime.timezone.utc, 'UTC' if sys.version_info >= (3, 6) else '+00:00'), (datetime.timezone(datetime.timedelta(hours=1, minutes=30)), '+01:30') ]) def test_tzinfo_to_string(tz, expected):