diff --git a/python/pyarrow/tests/test_pandas.py b/python/pyarrow/tests/test_pandas.py index 312bfdd36351c..d5c936df072ae 100644 --- a/python/pyarrow/tests/test_pandas.py +++ b/python/pyarrow/tests/test_pandas.py @@ -1854,6 +1854,15 @@ def test_table_str_to_categorical_without_na(self, string_type): table.to_pandas(strings_to_categorical=True, zero_copy_only=True) + # chunked array + result = table["strings"].to_pandas(strings_to_categorical=True) + expected = pd.Series(pd.Categorical(values), name="strings") + tm.assert_series_equal(result, expected) + + with pytest.raises(pa.ArrowInvalid): + table["strings"].to_pandas(strings_to_categorical=True, + zero_copy_only=True) + @pytest.mark.parametrize( "string_type", [pa.string(), pa.large_string(), pa.string_view()] ) @@ -1872,6 +1881,15 @@ def test_table_str_to_categorical_with_na(self, string_type): table.to_pandas(strings_to_categorical=True, zero_copy_only=True) + # chunked array + result = table["strings"].to_pandas(strings_to_categorical=True) + expected = pd.Series(pd.Categorical(values), name="strings") + tm.assert_series_equal(result, expected) + + with pytest.raises(pa.ArrowInvalid): + table["strings"].to_pandas(strings_to_categorical=True, + zero_copy_only=True) + # Regression test for ARROW-2101 def test_array_of_bytes_to_strings(self): converted = pa.array(np.array([b'x'], dtype=object), pa.string())