cloud-fan commented on code in PR #42828:
URL: https://github.com/apache/spark/pull/42828#discussion_r1338149416


##########
python/pyspark/sql/tests/test_dataframe.py:
##########
@@ -63,6 +62,51 @@
 
 
 class DataFrameTestsMixin:
+    def test_getitem_invalid_indices(self):
+        df = self.spark.sql(
+            "SELECT * FROM VALUES "
+            "(1, 1.1, 'a'), "
+            "(2, 2.2, 'b'), "
+            "(4, 4.4, 'c') "
+            "AS TAB(a, b, c)"
+        )
+
+        # accepted type and values
+        for index in [False, True, 0, 1, 2, -1, -2, -3]:
+            df[index]

Review Comment:
   If `df[index]` is already in pyspark for a while, I think it's fine to treat 
it as a shortcut of `df.i_th_col`. We shouldn't use `GetColumnByOrdinal` in 
this case, as it was added for Dataset Tuple encoding and it's guaranteed that 
we want to get the column from the direct child of the current plan node. But 
here, we can't guarantee this, as people can do 
`df1.select..filter...groupBy...select(df1[index])`



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to