Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions cpp/src/arrow/python/datetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ Result<std::string> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down