lidavidm commented on code in PR #13109:
URL: https://github.com/apache/arrow/pull/13109#discussion_r904379120


##########
python/pyarrow/_compute.pyx:
##########
@@ -2198,7 +2198,14 @@ cdef class Expression(_Weakrefable):
         -------
         cast : Expression
         """
-        options = CastOptions.safe(ensure_type(type))
+        if (safe is not None) and (options is not None):
+            raise ValueError(
+                "Must past only a value for 'safe' or only a value for 
'options'")

Review Comment:
   ```suggestion
                   "Must pass only a value for 'safe' or only a value for 
'options'")
   ```



##########
python/pyarrow/tests/test_compute.py:
##########
@@ -1702,13 +1702,33 @@ def test_logical():
 
 
 def test_cast():
+    arr = pa.array([1, 2, 3, 4], type='int64')
+    options = pc.CastOptions(pa.int8())
+
+    with pytest.raises(ValueError):
+        pc.cast(arr, target_type=None)
+
+    with pytest.raises(ValueError):
+        pc.cast(arr, 'int32', safe=True, options=options)
+
+    with pytest.raises(ValueError):
+        pc.cast(arr, 'int32', safe=False, options=options)
+
+    assert pc.cast(arr, 'int8', options=options) == pa.array(
+        [1, 2, 3, 4], type='int8')
+
     arr = pa.array([2 ** 63 - 1], type='int64')
+    allow_overflow_options = pc.CastOptions(
+        pa.int32(), allow_int_overflow=True)
 
     with pytest.raises(pa.ArrowInvalid):
         pc.cast(arr, 'int32')
 
     assert pc.cast(arr, 'int32', safe=False) == pa.array([-1], type='int32')
 
+    assert pc.cast(arr, 'int32', options=allow_overflow_options) == pa.array(
+        [-1], type='int32')

Review Comment:
   Now that I look at it…should we make the `type` an optional argument too? 
It's redundant with options (either you pass `type` and `safe`, or you pass 
`options`)



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