zhengruifeng commented on code in PR #53967:
URL: https://github.com/apache/spark/pull/53967#discussion_r2729731923


##########
python/pyspark/sql/conversion.py:
##########
@@ -1004,13 +1004,47 @@ class ArrowArrayToPandasConversion:
     @classmethod
     def convert_legacy(
         cls,
-        arr: "pa.Array",
+        arr: Union["pa.Array", "pa.ChunkedArray"],
         spark_type: DataType,
         *,
         timezone: Optional[str] = None,
         struct_in_pandas: Optional[str] = None,
         ndarray_as_list: bool = False,
-    ) -> "pd.Series":
+        df_for_struct: bool = False,
+    ) -> Union["pd.Series", "pd.DataFrame"]:
+        """
+        Parameters
+        ----------
+        arr : :class:`pyarrow.Array`
+        spark_type: target spark type, should always be specified
+        df_for_struct: when true, and spark type is a StructType, return a 
DataFrame.
+        """
+        import pyarrow as pa
+        import pandas as pd
+
+        assert isinstance(arr, (pa.Array, pa.ChunkedArray))
+
+        if df_for_struct and isinstance(spark_type, StructType):
+            import pyarrow.types as types
+
+            assert types.is_struct(arr.type)
+            assert len(spark_type.names) == len(arr.type.names), 
f"{spark_type} {arr.type} "
+
+            series = [
+                cls.convert_legacy(
+                    field_arr,
+                    spark_type=field.dataType,
+                    timezone=timezone,
+                    struct_in_pandas=struct_in_pandas,
+                    ndarray_as_list=ndarray_as_list,
+                    df_for_struct=False,  # always False for child fields
+                )
+                for field_arr, field in enumerate(zip(arr.flatten(), 
spark_type))

Review Comment:
   ah, good catch, thanks!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to