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 2020/10/07 08:20:57 UTC

[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #8349: ARROW-3080: [Python] Unify Arrow to Python object conversion paths

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



##########
File path: cpp/src/arrow/python/python_to_arrow.cc
##########
@@ -298,7 +298,14 @@ class PyValue {
           value = internal::PyDelta_to_us(dt);
           break;
         case TimeUnit::NANO:
-          value = internal::PyDelta_to_ns(dt);
+          if (internal::IsPandasTimedelta(obj)) {
+            OwnedRef nanos(PyObject_GetAttrString(obj, "nanoseconds"));
+            RETURN_IF_PYERROR();
+            RETURN_NOT_OK(internal::CIntFromPython(nanos.obj(), &value));
+            value += internal::PyDelta_to_ns(dt);

Review comment:
       Should something similar be needed for Timestamp (datetime) ?

##########
File path: python/pyarrow/tests/test_convert_builtin.py
##########
@@ -1894,18 +1937,30 @@ def test_dictionary_from_strings():
     assert a.dictionary.equals(expected_dictionary)
 
 
-def _has_unique_field_names(ty):
-    if isinstance(ty, pa.StructType):
-        field_names = [field.name for field in ty]
-        return len(set(field_names)) == len(field_names)
-    else:
-        return True
+@pytest.mark.parametrize('unit', ['s', 'ms', 'us', 'ns'])
+def test_duration_array_roundtrip_corner_cases(unit):
+    # corner case discovered by hypothesis
+    ty = pa.duration(unit)
+    arr = pa.array([-2147483000], type=ty)
+    restored = pa.array(arr.to_pylist(), type=ty)
+    assert arr.equals(restored)

Review comment:
       Do you know what was going wrong in this case? 

##########
File path: python/pyarrow/tests/test_convert_builtin.py
##########
@@ -1894,18 +1937,30 @@ def test_dictionary_from_strings():
     assert a.dictionary.equals(expected_dictionary)
 
 
-def _has_unique_field_names(ty):
-    if isinstance(ty, pa.StructType):
-        field_names = [field.name for field in ty]
-        return len(set(field_names)) == len(field_names)
-    else:
-        return True
+@pytest.mark.parametrize('unit', ['s', 'ms', 'us', 'ns'])
+def test_duration_array_roundtrip_corner_cases(unit):
+    # corner case discovered by hypothesis
+    ty = pa.duration(unit)
+    arr = pa.array([-2147483000], type=ty)
+    restored = pa.array(arr.to_pylist(), type=ty)
+    assert arr.equals(restored)
+
+
+@pytest.mark.pandas
+def test_duration_array_roundtrip_nanosecond_resolution_pandas_timedelta():
+    # corner case discovered by hypothesis

Review comment:
       Can you also mention the actual bug it is testing? (i.e. preserving the nanoseconds on conversion from a list of Timedelta objects, I think?)




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

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