You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/01 13:12:47 UTC

[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #12522: ARROW-15580: [Python] PyArrow imports pytz, which is not included as dependency

jorisvandenbossche commented on a change in pull request #12522:
URL: https://github.com/apache/arrow/pull/12522#discussion_r816755156



##########
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:
       This part needs to be indented one level less?




-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org