Skip to content

Commit

Permalink
Add tests for apacheGH-35040 and apacheGH-34901
Browse files Browse the repository at this point in the history
  • Loading branch information
danepitkin committed May 10, 2023
1 parent 057b81e commit 689fe59
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion python/pyarrow/tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_cast():
pa.scalar('foo').cast('int32')


def test_timestamp_to_string_cast():
def test_cast_timestamp_to_string():
# GH-35370
pytest.importorskip("pytz")
import pytz
Expand All @@ -304,6 +304,26 @@ def test_timestamp_to_string_cast():
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
int_scalar = pa.scalar(18014398509481983, type=pa.int64())
unsafe_cast = int_scalar.cast(pa.float64(), safe=False)
expected_unsafe_cast = pa.scalar(18014398509481983.0, type=pa.float64())
assert unsafe_cast == expected_unsafe_cast
with pytest.raises(pa.ArrowInvalid):
int_scalar.cast(pa.float64(), safe=True)


@pytest.mark.pandas
def test_timestamp():
import pandas as pd
Expand Down

0 comments on commit 689fe59

Please sign in to comment.