You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jorisvandenbossche (via GitHub)" <gi...@apache.org> on 2023/02/21 14:18:44 UTC

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #34275: GH-21761: [Python] Change array constructor to accept pyarrow array

jorisvandenbossche commented on code in PR #34275:
URL: https://github.com/apache/arrow/pull/34275#discussion_r1113127774


##########
python/pyarrow/array.pxi:
##########
@@ -232,6 +232,11 @@ def array(object obj, type=None, mask=None, size=None, from_pandas=None,
     else:
         c_from_pandas = from_pandas
 
+    if isinstance(obj, Array):
+        if type is not None and not obj.type.equals(type):
+            obj = obj.cast(type)

Review Comment:
   We probably should pass through the `safe` and `memory_pool` keywords to `cast` (`safe` can also easily be tested)



##########
python/pyarrow/tests/test_array.py:
##########
@@ -3381,3 +3381,15 @@ def test_struct_array_sort():
         {"a": 5, "b": "foo"},
         None
     ]
+
+
+def test_array_accepts_pyarrow_array():
+    arr = pa.array([1, 2, 3])
+    result = pa.array(arr)
+
+    assert arr == result
+
+    arr_uint = pa.array([1, 2, 3], type=pa.uint8())
+    result = pa.array(arr, type=pa.uint8())

Review Comment:
   Can you add an extra test where the passed `type` is different? (eg int64 in this case)



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