Github user BryanCutler commented on a diff in the pull request: https://github.com/apache/spark/pull/18378#discussion_r123326970 --- Diff: python/pyspark/sql/dataframe.py --- @@ -1750,6 +1751,29 @@ def _to_scala_map(sc, jm): return sc._jvm.PythonUtils.toScalaMap(jm) +def _to_numpy_type(dt): + """ + Convert a Spark SQL data type to Pandas data type. + """ + import numpy as np + if type(dt) == BooleanType: + return 'bool' + elif type(dt) == ByteType: + return 'int8' + elif type(dt) == ShortType: + return 'int16' + elif type(dt) == IntegerType: + return 'int32' + elif type(dt) == LongType: + return 'int64' + elif type(dt) == FloatType: + return 'float32' + elif type(dt) == DoubleType: + return 'float64' + else: + return 'object' --- End diff -- I think it might cause problems to have all non-primitive types as object. Things like timestamps will be inferred form a datetime object, for example: ```python In [10]: pdf = pd.DataFrame.from_records([(1.0, 1, "a", datetime.datetime.now())]) In [11]: pdf.dtypes Out[11]: 0 float64 1 int64 2 object 3 datetime64[ns] dtype: object In [12]: pdf.astype({0: "float32", 1: "int32", 2: "object", 3: "object"}).dtypes Out[12]: 0 float32 1 int32 2 object 3 object dtype: object ```
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org