pralabhkumar commented on a change in pull request #34401:
URL: https://github.com/apache/spark/pull/34401#discussion_r738109398



##########
File path: python/pyspark/sql/pandas/conversion.py
##########
@@ -151,7 +151,17 @@ def toPandas(self) -> "PandasDataFrameLike":
                                     _convert_map_items_to_dict(pdf[field.name])
                         return pdf
                     else:
-                        return pd.DataFrame.from_records([], 
columns=self.columns)
+                        pdf = pd.DataFrame.from_records([], 
columns=self.columns)
+                        df = pd.DataFrame()
+                        for fieldIdx, field in enumerate(self.schema):
+                            pandas_type = \
+                                
PandasConversionMixin._to_corrected_pandas_type(field.dataType)
+                            column_name = self.schema[fieldIdx].name
+                            series = pdf.iloc[:, fieldIdx]
+                            if pandas_type is not None:
+                                series = series.astype(pandas_type, copy=False)
+                            df.insert(fieldIdx, column_name, series, 
allow_duplicates=True)

Review comment:
       @HyukjinKwon Thx for the comment .Let me try the simpler way




-- 
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