You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "BeishaoCao-db (via GitHub)" <gi...@apache.org> on 2023/05/31 16:01:24 UTC

[GitHub] [spark] BeishaoCao-db commented on a diff in pull request #41396: [SPARK-43892][PYTHON] add autocomplete support for `df[|]` in `pyspark.sql.dataframe.DataFrame`

BeishaoCao-db commented on code in PR #41396:
URL: https://github.com/apache/spark/pull/41396#discussion_r1211959331


##########
python/pyspark/sql/dataframe.py:
##########
@@ -4868,6 +4868,22 @@ def freqItems(
             self._jdf.stat().freqItems(_to_seq(self._sc, cols), support), self.sparkSession
         )
 
+    def _ipython_key_completions_(self) -> List[str]:
+        """Returns the names of columns in this :class:`DataFrame`.
+        
+        Examples
+        --------
+        >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], ["age", "name"])
+        >>> df._ipython_key_completions_()
+        ['age', 'name']
+
+        Would return illegal identifiers.
+        >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], ["age 1", "name?1"])
+        >>> df._ipython_key_completions_()
+        ['age 1', 'name?1']
+        """
+        return self.columns

Review Comment:
   __dir__ will return all attr, seems df[] can only accept columns:
   
   <img width="1916" alt="Screenshot 2023-05-31 at 9 00 15 AM" src="https://github.com/apache/spark/assets/109033553/b9c28510-c646-424d-b783-795caf7872db">
   



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