From b33daf459f636d167fb384a922bd4f312e5b4dfb Mon Sep 17 00:00:00 2001 From: Afonso Oliveira Date: Fri, 13 Nov 2026 10:49:19 +0000 Subject: [PATCH] GH-55486: [Python] Make test_asarray run and update it to the current Scalar API Use the NumPy marker for test_asarray and test_chunked_array_asarray so both tests run with or without pandas. Convert the Arrow scalars with as_py() before comparing them to Python integers. --- python/pyarrow/tests/test_array.py | 9 ++++----- python/pyarrow/tests/test_table.py | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index ca063bc6b69..7a4328ce9f9 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -316,16 +316,15 @@ def test_to_pandas_zero_copy(): series.sum() -@pytest.mark.nopandas -@pytest.mark.pandas +@pytest.mark.numpy def test_asarray(): - # ensure this is tested both when pandas is present or not (ARROW-6564) + # Run with or without pandas (ARROW-6564). arr = pa.array(range(4)) - # The iterator interface gives back an array of Int64Scalar's + # Iteration gives Scalar objects, preserved by NumPy's object array. np_arr = np.asarray([_ for _ in arr]) - assert np_arr.tolist() == [0, 1, 2, 3] + assert [value.as_py() for value in np_arr] == [0, 1, 2, 3] assert np_arr.dtype == np.dtype('O') assert isinstance(np_arr[0], pa.Int64Scalar) diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py index 9a2a99b4e53..f23d7b2a936 100644 --- a/python/pyarrow/tests/test_table.py +++ b/python/pyarrow/tests/test_table.py @@ -420,10 +420,9 @@ def test_to_pandas_empty_table(): tm.assert_frame_equal(result, df.iloc[:0]) -@pytest.mark.pandas -@pytest.mark.nopandas +@pytest.mark.numpy def test_chunked_array_asarray(): - # ensure this is tested both when pandas is present or not (ARROW-6564) + # Run with or without pandas (ARROW-6564). data = [ pa.array([0]),