You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "AlenkaF (via GitHub)" <gi...@apache.org> on 2023/05/11 08:22:04 UTC

[GitHub] [arrow] AlenkaF commented on a diff in pull request #35395: GH-35040: [Python] Pyarrow scalar cast uses compute kernel

AlenkaF commented on code in PR #35395:
URL: https://github.com/apache/arrow/pull/35395#discussion_r1190806480


##########
python/pyarrow/tests/test_scalars.py:
##########
@@ -295,6 +295,35 @@ def test_cast():
         pa.scalar('foo').cast('int32')
 
 
+def test_cast_timestamp_to_string():
+    # GH-35370
+    pytest.importorskip("pytz")
+    import pytz
+    dt = datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=pytz.utc)
+    ts = pa.scalar(dt, type=pa.timestamp("ns", tz="UTC"))
+    assert ts.cast(pa.string()) == pa.scalar('2000-01-01 00:00:00.000000000Z')
+
+
+def test_cast_float_to_int():
+    # GH-35040
+    float_scalar = pa.scalar(1.5, type=pa.float64())
+    unsafe_cast = float_scalar.cast(pa.int64(), safe=False)
+    expected_unsafe_cast = pa.scalar(1, type=pa.int64())
+    assert unsafe_cast == expected_unsafe_cast
+    with pytest.raises(pa.ArrowInvalid):
+        float_scalar.cast(pa.int64(), safe=True)
+
+
+def test_cast_int_to_float():
+    # GH-34901

Review Comment:
   Thank you for adding the tests!
   
   Just to check I understood the 34901 issue correctly: the behaviour when casting arrays was correct (default is safe) and so the change should be made in scalars too (default being safe)? As the default in `pyarrow.compute.cast` is `True` for `safe` argument, then we get this by default in `cast` for scalars with this PR.



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