HyukjinKwon commented on a change in pull request #34401:
URL: https://github.com/apache/spark/pull/34401#discussion_r737943724
##########
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:
Is there simpler and easier way to assign types to an empty pandas
DataFrame? The current way looks too messy.
--
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]