ueshin opened a new pull request #28210: [SPARK-31441] Support duplicated 
column names for toPandas with arrow execution.
URL: https://github.com/apache/spark/pull/28210
 
 
   ### What changes were proposed in this pull request?
   
   This PR is adding support duplicated column names for `toPandas` with Arrow 
execution.
   
   ### Why are the changes needed?
   
   When we execute `toPandas()` with Arrow execution, it fails if the column 
names have duplicates.
   
   ```py
   >>> spark.sql("select 1 v, 1 v").toPandas()
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/path/to/lib/python3.7/site-packages/pyspark/sql/dataframe.py", line 
2132, in toPandas
       pdf = table.to_pandas()
     File "pyarrow/array.pxi", line 441, in 
pyarrow.lib._PandasConvertible.to_pandas
     File "pyarrow/table.pxi", line 1367, in pyarrow.lib.Table._to_pandas
     File "/path/to/lib/python3.7/site-packages/pyarrow/pandas_compat.py", line 
653, in table_to_blockmanager
       columns = _deserialize_column_index(table, all_columns, column_indexes)
     File "/path/to/lib/python3.7/site-packages/pyarrow/pandas_compat.py", line 
704, in _deserialize_column_index
       columns = _flatten_single_level_multiindex(columns)
     File "/path/to/lib/python3.7/site-packages/pyarrow/pandas_compat.py", line 
937, in _flatten_single_level_multiindex
       raise ValueError('Found non-unique column index')
   ValueError: Found non-unique column index
   ```
   
   ### Does this PR introduce any user-facing change?
   <!--
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If no, write 'No'.
   -->
   Yes, previously we will face an error above, but after this PR, we will see 
the result:
   
   ```py
   >>> spark.sql("select 1 v, 1 v").toPandas()
      v  v
   0  1  1
   ```
   
   ### How was this patch tested?
   
   Added and modified related tests.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to