Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,11 +1725,14 @@ def toPandas(self):
dtype = {}
for field in self.schema:
pandas_type = _to_corrected_pandas_type(field.dataType)
if (pandas_type):
if pandas_type is not None:
dtype[field.name] = pandas_type

df = pd.DataFrame.from_records(self.collect(), columns=self.columns)
return df.astype(dtype, copy=False)
pdf = pd.DataFrame.from_records(self.collect(), columns=self.columns)

for f, t in dtype.items():
pdf[f] = pdf[f].astype(t)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need copying data?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh!

return pdf

##########################################################################################
# Pandas compatibility
Expand Down