Skip to content

Commit 357a798

Browse files
authored
Merge pull request #7 from HyukjinKwon/pandas-astype
Work around astype with columns in Pandas < 0.19.0
2 parents dfaa392 + 6702ad1 commit 357a798

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

python/pyspark/sql/dataframe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,11 +1725,14 @@ def toPandas(self):
17251725
dtype = {}
17261726
for field in self.schema:
17271727
pandas_type = _to_corrected_pandas_type(field.dataType)
1728-
if (pandas_type):
1728+
if pandas_type is not None:
17291729
dtype[field.name] = pandas_type
17301730

1731-
df = pd.DataFrame.from_records(self.collect(), columns=self.columns)
1732-
return df.astype(dtype, copy=False)
1731+
pdf = pd.DataFrame.from_records(self.collect(), columns=self.columns)
1732+
1733+
for f, t in dtype.items():
1734+
pdf[f] = pdf[f].astype(t, copy=False)
1735+
return pdf
17331736

17341737
##########################################################################################
17351738
# Pandas compatibility

0 commit comments

Comments
 (0)