GitHub user dongjoon-hyun opened a pull request:
https://github.com/apache/spark/pull/13097
[SPARK-15244][PYSPARK] Type of column name created with createDataFrame is
not consistent.
## What changes were proposed in this pull request?
**createDataFrame** returns inconsistent types for column names.
```python
>>> schema = StructType([StructField(u"col", StringType())])
>>> df1 = sqlContext.createDataFrame([("a",)], schema)
>>> df1.columns # "col" is str
['col']
>>> df2 = sqlContext.createDataFrame([("a",)], [u"col"])
>>> df2.columns # "col" is unicode
[u'col']
```
The reason is only **StructField** has the following code.
```
if not isinstance(name, str):
name = name.encode('utf-8')
```
This PR adds the similar logic into **createDataFrame** for consistency.
```
if isinstance(schema, list):
schema = [x.encode('utf-8') if isinstance(x, unicode) else x for x in
schema]
```
## How was this patch tested?
Pass the Jenkins test (with new python doctest)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/dongjoon-hyun/spark SPARK-15244
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/13097.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #13097
----
commit c47b12b010ae0a107d54e03f166cfd9b79ae92a5
Author: Dongjoon Hyun <[email protected]>
Date: 2016-05-13T09:09:30Z
[SPARK-15244][PYSPARK] Type of column name created with createDataFrame is
not consistent.
----
---
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]