Github user davies commented on a diff in the pull request: https://github.com/apache/spark/pull/8647#discussion_r39213684 --- Diff: python/pyspark/sql/column.py --- @@ -341,7 +343,30 @@ def cast(self, dataType): raise TypeError("unexpected type: %s" % type(dataType)) return Column(jc) - astype = cast + @ignore_unicode_prefix + @since(1.3) + def astype(self, dataType): + """ Convert the column into type ``dataType``. + + >>> df.select(df.age.astype("string").alias('ages')).collect() + [Row(ages=u'2'), Row(ages=u'5')] + >>> df.select(df.age.astype(StringType()).alias('ages')).collect() + [Row(ages=u'2'), Row(ages=u'5')] + + (Note : astype is alias for cast) + """ + if isinstance(dataType, basestring): + jc = self._jc.astype(dataType) + elif isinstance(dataType, DataType): + sc = SparkContext._active_spark_context + ssql_ctx = sc._jvm.SQLContext(sc._jsc.sc()) + jdt = ssql_ctx.parseDataType(dataType.json()) + jc = self._jc.astype(jdt) + else: + raise TypeError("unexpected type: %s" % type(dataType)) + return Column(jc) + + # astype = cast --- End diff -- remove this
--- 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