milesgranger commented on code in PR #14106:
URL: https://github.com/apache/arrow/pull/14106#discussion_r977321737


##########
python/pyarrow/tests/test_extension_type.py:
##########
@@ -517,10 +517,31 @@ def test_cast_kernel_on_extension_arrays():
     assert isinstance(casted, pa.ChunkedArray)
 
 
-def test_casting_to_extension_type_raises():
-    arr = pa.array([1, 2, 3, 4], pa.int64())
-    with pytest.raises(pa.ArrowNotImplementedError):
-        arr.cast(IntegerType())
[email protected]("data,ty", (
+    ([1, 2], pa.int32),
+    ([1, 2], pa.int64),
+    (["1", "2"], pa.string),
+    ([b"1", b"2"], pa.binary),
+    ([1.0, 2.0], pa.float32),
+    ([1.0, 2.0], pa.float64)
+))
+def test_casting_to_extension_type(data, ty):
+    arr = pa.array(data, ty())
+    out = arr.cast(IntegerType())
+    assert isinstance(out, pa.ExtensionArray)
+    assert out.type == IntegerType()
+    assert out.to_pylist() == [1, 2]

Review Comment:
   There are indeed some C++ testing, such as `IntToExtensionTypeDowncast` 
(works only when setting options to allow truncation) and 
`PrimitiveToExtension` (type which is impossible to cast)
   
   Happy to add them to Python as well.



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

Reply via email to