You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/01/18 09:27:07 UTC

[GitHub] [spark] dchvn opened a new pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

dchvn opened a new pull request #35240:
URL: https://github.com/apache/spark/pull/35240


   ### What changes were proposed in this pull request?
   Fix select subset with duplicated columns of ps.DataFrame
   
   ### Why are the changes needed?
   Currently, when select subset with duplicated columns of ps.DataFrame we will face an exception 
   ```python-traceback
   ValueError: Length mismatch: Expected axis has 4 elements, new values have 2 elements
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes,
   
   Before this PR
   ```python
   >>> psdf
      a
   0  1
   1  2
   2  3
   3  4
   >>> psdf[['a', 'a']]
   Traceback (most recent call last):
     ...
     File "/u02/venv3.9-2/lib/python3.9/site-packages/pandas/core/internals/base.py", line 57, in _validate_set_axis
       raise ValueError(
   ValueError: Length mismatch: Expected axis has 4 elements, new values have 2 elements
   
   >>> psdf.loc[:, ['a', 'a']]
   Traceback (most recent call last):
     ...
     File "/u02/venv3.9-2/lib/python3.9/site-packages/pandas/core/internals/base.py", line 57, in _validate_set_axis
       raise ValueError(
   ValueError: Length mismatch: Expected axis has 4 elements, new values have 2 elements 
   ```
   
   After this PR
   ```python
   >>> pdf[['a', 'a']]
      a  a
   0  1  1
   1  2  2
   2  3  3
   3  4  4
   
   >>> pdf.loc[:, ['a', 'a']]
      a  a
   0  1  1
   1  2  2
   2  3  3
   3  4  4
   
   ```
   
   ### How was this patch tested?
   unit test
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dchvn commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
dchvn commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787280890



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       Should we change the [docs](https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/best_practices.html?highlight=duplicate#do-not-use-duplicated-column-names)  in this PR




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] itholic commented on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
itholic commented on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018104004


   I'm just worrying that unexpected errors may occur in random places after creating duplicated columns since we're not officially support it.
   
   For example,
   
   ```python
   >>> psdf[['a', 'a', 'a']].a
   Traceback (most recent call last):
   ...
   TypeError: to_string() got an unexpected keyword argument 'name'
   ```
   
   whereas pandas support it
   
   ```python
   >>> pdf[['a', 'a', 'a']].a
             a  a  a
   0.480706  1  1  1
   0.670385  2  2  2
   0.051040  3  3  3
   0.815093  4  4  4
   0.567992  5  5  5
   0.740033  6  6  6
   0.646050  7  7  7
   0.058224  8  8  8
   0.939080  9  9  9
   ```


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] itholic edited a comment on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
itholic edited a comment on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018104004






-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Yikun commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
Yikun commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787285078



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       >  Actually pandas API on Spark does not officially support duplicated column names for now.
   
   learned
   
   > Should we change the docs in this PR
   ```
           import pyspark.pandas as ps
           psdf = ps.DataFrame({'a': [1, 2], 'b': [3, 4]})
           psdf.columns = ["a", "a"]
           print(psdf)
   ```
   FYI, this still raise the exception `pyspark.sql.utils.AnalysisException: Reference 'a' is ambiguous, could be: a, a.`.
   
   And sorry late to say, I think this PR is only for `self combine` case, right? so another option for original PR, since we have made it clear in the document that the same column is not supported, should we directly throw an exception when self combine? Let's see other idea.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] phofl commented on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
phofl commented on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018010679


   Just as a note from the pandas site: The behavior as is on pandas is correct. Selecting duplicated columns twice should duplicate them again. This is the same as when selecting a unique column twice.


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Yikun commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
Yikun commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787285078



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       >  Actually pandas API on Spark does not officially support duplicated column names for now.
   
   learned
   
   > Should we change the docs in this PR
   ```
           import pyspark.pandas as ps
           psdf = ps.DataFrame({'a': [1, 2], 'b': [3, 4]})
           psdf.columns = ["a", "a"]
           print(psdf)
   ```
   FYI, this still raise the exception `pyspark.sql.utils.AnalysisException: Reference 'a' is ambiguous, could be: a, a.`. So, 
   seems that the document is still valid
   
   And sorry late to say, I think this PR is only for `self combine` case, right? so another option for original PR, since we have made it clear in the document that the same column is not supported, should we directly throw an exception when self combine? Let's see other idea.

##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       >  Actually pandas API on Spark does not officially support duplicated column names for now.
   
   learned
   
   > Should we change the docs in this PR
   ```
           import pyspark.pandas as ps
           psdf = ps.DataFrame({'a': [1, 2], 'b': [3, 4]})
           psdf.columns = ["a", "a"]
           print(psdf)
   ```
   FYI, this still raise the exception `pyspark.sql.utils.AnalysisException: Reference 'a' is ambiguous, could be: a, a.`. So, seems that the document is still valid
   
   And sorry late to say, I think this PR is only for `self combine` case, right? so another option for original PR, since we have made it clear in the document that the same column is not supported, should we directly throw an exception when self combine? Let's see other idea.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dchvn commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
dchvn commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787280415



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       > can we do `pdf[~pdf.columns.duplicated()][data_columns]`?
   
   I think `pdf[~pdf.columns.duplicated()]` is used to select rows. Do you mind if I keep using `.loc`
   




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dchvn commented on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
dchvn commented on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018137351


   @itholic Thanks for you investigation. I will raise an exception to continue my original PR.
   I have tested the case you mentioned and updated new test to cover it.


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] itholic edited a comment on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
itholic edited a comment on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018104004


   I'm just worrying about that unexpected errors may occur on the resulting DataFrame after creating duplicated columns since we're not officially support it.
   
   For example,
   
   ```python
   >>> psdf[['a', 'a', 'a']].a
   Traceback (most recent call last):
   ...
   TypeError: to_string() got an unexpected keyword argument 'name'
   ```
   
   whereas pandas support it
   
   ```python
   >>> pdf[['a', 'a', 'a']].a
             a  a  a
   0.480706  1  1  1
   0.670385  2  2  2
   0.051040  3  3  3
   0.815093  4  4  4
   0.567992  5  5  5
   0.740033  6  6  6
   0.646050  7  7  7
   0.058224  8  8  8
   0.939080  9  9  9
   ```
   
   So, how about we just raise the proper exception for now as mentioned at  https://github.com/apache/spark/pull/35240#discussion_r787319309 ?


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787319309



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       Maybe throwing an exception is an idea too .. actually we have a lot of places like this, not only here. so let's just fix this it first, and revisit the duplicate names later separately.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dchvn commented on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
dchvn commented on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1015224778


   CC @Yikun @HyukjinKwon @ueshin @itholic Please take a look when you find sometime, thanks!


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Yikun commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
Yikun commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787285078



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       >  Actually pandas API on Spark does not officially support duplicated column names for now.
   
   learned
   
   > Should we change the docs in this PR
   ```
           import pyspark.pandas as ps
           psdf = ps.DataFrame({'a': [1, 2], 'b': [3, 4]})
           psdf.columns = ["a", "a"]
           print(psdf)
   ```
   FYI, this still raise the exception `pyspark.sql.utils.AnalysisException: Reference 'a' is ambiguous, could be: a, a.`.
   
   And sorry late to say, I think this PR is only for `self combine` case, right? so another option for original PR, since we have made it clear in the document that the same column is not supported, should we directly throw an exception when self combine?




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] itholic edited a comment on pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
itholic edited a comment on pull request #35240:
URL: https://github.com/apache/spark/pull/35240#issuecomment-1018104004


   I'm just worrying about that unexpected errors may occur on the resulting DataFrame after creating duplicated columns since we're not officially support it.
   
   For example,
   
   ```python
   >>> psdf[['a', 'a', 'a']].a
   Traceback (most recent call last):
   ...
   TypeError: to_string() got an unexpected keyword argument 'name'
   ```
   
   whereas pandas support it
   
   ```python
   >>> pdf[['a', 'a', 'a']].a
             a  a  a
   0.480706  1  1  1
   0.670385  2  2  2
   0.051040  3  3  3
   0.815093  4  4  4
   0.567992  5  5  5
   0.740033  6  6  6
   0.646050  7  7  7
   0.058224  8  8  8
   0.939080  9  9  9
   ```


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787241011



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       ohh. sorry I missed https://spark.apache.org/docs/latest/api/python/user_guide/pandas_on_spark/best_practices.html?highlight=duplicate#do-not-use-duplicated-column-names. Actually pandas API on Spark does not officially support duplicated column names for now.
   
   But It think we can fix this as the fix seems minimized. BTW, can we do `pdf[~pdf.columns.duplicated()][data_columns]`?




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787241167



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       Otherwise LGTM




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dchvn commented on a change in pull request #35240: [SPARK-37930][PYTHON] Fix DataFrame select subset with duplicated columns

Posted by GitBox <gi...@apache.org>.
dchvn commented on a change in pull request #35240:
URL: https://github.com/apache/spark/pull/35240#discussion_r787308573



##########
File path: python/pyspark/pandas/internal.py
##########
@@ -1143,7 +1143,10 @@ def restore_index(
             drop = index_field not in data_columns
             pdf = pdf.set_index(index_field, drop=drop, append=append)
             append = True
-        pdf = pdf[data_columns]
+
+        # SPARK-37930: Fix DataFrame select subset with duplicated columns
+        # Remove duplicated columns before select `data_columns`
+        pdf = pdf.loc[:, ~pdf.columns.duplicated()][data_columns]

Review comment:
       @Yikun Thanks for the clarification. I prefer to change behavior to follow pandas, but do not mind if we decide to keep this difference.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org