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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]