You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "fangchenli (via GitHub)" <gi...@apache.org> on 2026/01/11 23:06:29 UTC

[PR] [SPARK-54944][Python] Add tests for pa.Array.to_pandas with default arguments [spark]

fangchenli opened a new pull request, #53763:
URL: https://github.com/apache/spark/pull/53763

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'common/utils/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Add tests for pa.Array.to_pandas with default arguments
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   We want to monitor changes in PyArrow's behavior.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as new features, bug fixes, or other behavior changes. Documentation-only updates are not considered user-facing changes.
   
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Unit tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   Generated-by: Claude Opus 4.5


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][Python] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "Yicong-Huang (via GitHub)" <gi...@apache.org>.
Yicong-Huang commented on PR #53763:
URL: https://github.com/apache/spark/pull/53763#issuecomment-3741011611

   I think for test only PRs we need to add [TESTS] in title


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][PYTHON][TESTS] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #53763:
URL: https://github.com/apache/spark/pull/53763#issuecomment-4375693454

   We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
   If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][Python][TESTS] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "fangchenli (via GitHub)" <gi...@apache.org>.
fangchenli commented on code in PR #53763:
URL: https://github.com/apache/spark/pull/53763#discussion_r2688275627


##########
python/pyspark/tests/upstream/pyarrow/test_pyarrow_array_to_pandas.py:
##########
@@ -0,0 +1,429 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Tests for PyArrow pa.Array.to_pandas with default arguments.
+
+This module tests how PyArrow converts Arrow arrays to pandas Series using
+default arguments. PySpark uses pa.Array.to_pandas() to convert Arrow data
+to numpy-backed pandas DataFrames for pandas UDFs.
+
+With default arguments, to_pandas() converts Arrow arrays to numpy-backed
+pandas Series, which is important for PySpark's type handling.
+"""
+
+import datetime
+import math
+import unittest
+from decimal import Decimal
+
+from pyspark.testing.utils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+
+@unittest.skipIf(
+    not have_pyarrow or not have_pandas,
+    pyarrow_requirement_message if not have_pyarrow else pandas_requirement_message,
+)
+class PyArrowArrayToPandasTests(unittest.TestCase):
+    """Test pa.Array.to_pandas with default arguments."""
+
+    def test_integer_types(self):
+        """Test conversion of integer arrays to pandas."""
+        import numpy as np
+        import pandas as pd
+        import pyarrow as pa
+
+        # (arrow_type, values, expected_numpy_dtype)
+        test_cases = [

Review Comment:
   > are there ways to convert to ArrowDtype? or maybe that's not default arguments and belong to another test?
   
   That is not the default, and belongs to another test.



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][PYTHON][TESTS] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #53763: [SPARK-54944][PYTHON][TESTS] Add tests for pa.Array.to_pandas with default arguments
URL: https://github.com/apache/spark/pull/53763


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][Python] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #53763:
URL: https://github.com/apache/spark/pull/53763#issuecomment-3736253740

   ## JIRA Issue Information
   
   === Sub-task SPARK-54944 ===
   Summary: Add tests for pa.Array.to_pandas with default arguments
   Assignee: None
   Status: Open
   Affected: ["4.2.0"]
   
   ---
   *This comment was automatically generated by GitHub Actions*


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][Python] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "Yicong-Huang (via GitHub)" <gi...@apache.org>.
Yicong-Huang commented on code in PR #53763:
URL: https://github.com/apache/spark/pull/53763#discussion_r2684278103


##########
python/pyspark/tests/upstream/pyarrow/test_pyarrow_array_to_pandas.py:
##########
@@ -0,0 +1,429 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Tests for PyArrow pa.Array.to_pandas with default arguments.
+
+This module tests how PyArrow converts Arrow arrays to pandas Series using
+default arguments. PySpark uses pa.Array.to_pandas() to convert Arrow data
+to numpy-backed pandas DataFrames for pandas UDFs.
+
+With default arguments, to_pandas() converts Arrow arrays to numpy-backed
+pandas Series, which is important for PySpark's type handling.
+"""
+
+import datetime
+import math
+import unittest
+from decimal import Decimal
+
+from pyspark.testing.utils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+
+@unittest.skipIf(
+    not have_pyarrow or not have_pandas,
+    pyarrow_requirement_message if not have_pyarrow else pandas_requirement_message,
+)
+class PyArrowArrayToPandasTests(unittest.TestCase):
+    """Test pa.Array.to_pandas with default arguments."""
+
+    def test_integer_types(self):

Review Comment:
   for `to_pandas` we have seen many OOM and SEGFAULT issues in PySpark, which underneath uses PyArrow's `to_pandas`. I hope we can cover more types especially for nested struct/list/json.



##########
python/pyspark/tests/upstream/pyarrow/test_pyarrow_array_to_pandas.py:
##########
@@ -0,0 +1,429 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Tests for PyArrow pa.Array.to_pandas with default arguments.
+
+This module tests how PyArrow converts Arrow arrays to pandas Series using
+default arguments. PySpark uses pa.Array.to_pandas() to convert Arrow data
+to numpy-backed pandas DataFrames for pandas UDFs.
+
+With default arguments, to_pandas() converts Arrow arrays to numpy-backed
+pandas Series, which is important for PySpark's type handling.
+"""
+
+import datetime
+import math
+import unittest
+from decimal import Decimal
+
+from pyspark.testing.utils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+
+@unittest.skipIf(
+    not have_pyarrow or not have_pandas,
+    pyarrow_requirement_message if not have_pyarrow else pandas_requirement_message,
+)
+class PyArrowArrayToPandasTests(unittest.TestCase):
+    """Test pa.Array.to_pandas with default arguments."""
+
+    def test_integer_types(self):
+        """Test conversion of integer arrays to pandas."""
+        import numpy as np
+        import pandas as pd
+        import pyarrow as pa
+
+        # (arrow_type, values, expected_numpy_dtype)
+        test_cases = [
+            (pa.int8(), [1, 2, 3], np.int8),
+            (pa.int16(), [1, 2, 3], np.int16),
+            (pa.int32(), [1, 2, 3], np.int32),
+            (pa.int64(), [1, 2, 3], np.int64),
+            (pa.uint8(), [1, 2, 3], np.uint8),
+            (pa.uint16(), [1, 2, 3], np.uint16),
+            (pa.uint32(), [1, 2, 3], np.uint32),
+            (pa.uint64(), [1, 2, 3], np.uint64),
+        ]
+
+        for arrow_type, values, expected_dtype in test_cases:
+            arr = pa.array(values, type=arrow_type)
+            series = arr.to_pandas()
+            self.assertIsInstance(series, pd.Series)
+            self.assertEqual(
+                series.dtype,
+                expected_dtype,
+                f"Dtype mismatch for {arrow_type}: expected {expected_dtype}, got {series.dtype}",
+            )
+            self.assertEqual(series.tolist(), values)
+
+    def test_integer_with_nulls(self):
+        """Test conversion of nullable integer arrays - converts to float64 by default."""
+        import numpy as np
+        import pandas as pd
+        import pyarrow as pa
+
+        # With nulls, integers convert to float64 by default (numpy doesn't have nullable int)
+        arr = pa.array([1, None, 3], type=pa.int64())
+        series = arr.to_pandas()

Review Comment:
   how about NaN?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-54944][Python] Add tests for pa.Array.to_pandas with default arguments [spark]

Posted by "Yicong-Huang (via GitHub)" <gi...@apache.org>.
Yicong-Huang commented on code in PR #53763:
URL: https://github.com/apache/spark/pull/53763#discussion_r2684281401


##########
python/pyspark/tests/upstream/pyarrow/test_pyarrow_array_to_pandas.py:
##########
@@ -0,0 +1,429 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""
+Tests for PyArrow pa.Array.to_pandas with default arguments.
+
+This module tests how PyArrow converts Arrow arrays to pandas Series using
+default arguments. PySpark uses pa.Array.to_pandas() to convert Arrow data
+to numpy-backed pandas DataFrames for pandas UDFs.
+
+With default arguments, to_pandas() converts Arrow arrays to numpy-backed
+pandas Series, which is important for PySpark's type handling.
+"""
+
+import datetime
+import math
+import unittest
+from decimal import Decimal
+
+from pyspark.testing.utils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+
+@unittest.skipIf(
+    not have_pyarrow or not have_pandas,
+    pyarrow_requirement_message if not have_pyarrow else pandas_requirement_message,
+)
+class PyArrowArrayToPandasTests(unittest.TestCase):
+    """Test pa.Array.to_pandas with default arguments."""
+
+    def test_integer_types(self):
+        """Test conversion of integer arrays to pandas."""
+        import numpy as np
+        import pandas as pd
+        import pyarrow as pa
+
+        # (arrow_type, values, expected_numpy_dtype)
+        test_cases = [

Review Comment:
   are there ways to convert to ArrowDtype? or maybe that's not default arguments and belong to another test?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org