AlenkaF commented on a change in pull request #12522: URL: https://github.com/apache/arrow/pull/12522#discussion_r816758829
########## File path: cpp/src/arrow/python/datetime.cc ########## @@ -391,37 +391,43 @@ Result<std::string> PyTZInfo_utcoffset_hhmm(PyObject* pytzinfo) { Result<PyObject*> StringToTzinfo(const std::string& tz) { util::string_view sign_str, hour_str, minute_str; OwnedRef pytz; - RETURN_NOT_OK(internal::ImportModule("pytz", &pytz)); - if (MatchFixedOffset(tz, &sign_str, &hour_str, &minute_str)) { - int sign = -1; - if (sign_str == "+") { - sign = 1; - } - OwnedRef fixed_offset; - RETURN_NOT_OK(internal::ImportFromModule(pytz.obj(), "FixedOffset", &fixed_offset)); - uint32_t minutes, hours; - if (!::arrow::internal::ParseUnsigned(hour_str.data(), hour_str.size(), &hours) || - !::arrow::internal::ParseUnsigned(minute_str.data(), minute_str.size(), - &minutes)) { - return Status::Invalid("Invalid timezone: ", tz); - } - OwnedRef total_minutes(PyLong_FromLong( - sign * ((static_cast<int>(hours) * 60) + static_cast<int>(minutes)))); - RETURN_IF_PYERROR(); - auto tzinfo = - PyObject_CallFunctionObjArgs(fixed_offset.obj(), total_minutes.obj(), NULL); - RETURN_IF_PYERROR(); - return tzinfo; + if (internal::ImportModule("pytz", &pytz).ok()) { + RETURN_NOT_OK(internal::ImportModule("pytz", &pytz)); + + if (MatchFixedOffset(tz, &sign_str, &hour_str, &minute_str)) { + int sign = -1; + if (sign_str == "+") { + sign = 1; + } + OwnedRef fixed_offset; + RETURN_NOT_OK(internal::ImportFromModule(pytz.obj(), "FixedOffset", &fixed_offset)); + uint32_t minutes, hours; + if (!::arrow::internal::ParseUnsigned(hour_str.data(), hour_str.size(), &hours) || + !::arrow::internal::ParseUnsigned(minute_str.data(), minute_str.size(), + &minutes)) { + return Status::Invalid("Invalid timezone: ", tz); + } + OwnedRef total_minutes(PyLong_FromLong( + sign * ((static_cast<int>(hours) * 60) + static_cast<int>(minutes)))); + RETURN_IF_PYERROR(); + auto tzinfo = + PyObject_CallFunctionObjArgs(fixed_offset.obj(), total_minutes.obj(), NULL); + RETURN_IF_PYERROR(); + return tzinfo; + } + + OwnedRef timezone; Review comment: Yes indeed. Will correct - it will resolve the liner CI error also. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org