Github user BryanCutler commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18378#discussion_r123325897
  
    --- Diff: python/pyspark/sql/dataframe.py ---
    @@ -1721,7 +1721,8 @@ def toPandas(self):
             1    5    Bob
             """
             import pandas as pd
    -        return pd.DataFrame.from_records(self.collect(), 
columns=self.columns)
    +        dtype = {field.name: _to_numpy_type(field.dataType) for field in 
self.schema}
    +        return pd.DataFrame.from_records(self.collect(), 
columns=self.columns).astype(dtype)
    --- End diff --
    
    This is probably the easiest way to assign the types, but data is still 
loaded and inferred then the `astype` will then cast the data and I'm not sure 
if it will make a pass over the data or do it lazily.  A more ideal way would 
be to not use `from_records` but then I think the data would need to be broken 
up into columns.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to