HyukjinKwon commented on a change in pull request #29699:
URL: https://github.com/apache/spark/pull/29699#discussion_r487744634



##########
File path: python/pyspark/sql/column.py
##########
@@ -329,6 +329,31 @@ def getField(self, name):
                 DeprecationWarning)
         return self[name]
 
+    @since(3.1)
+    def withField(self, fieldName, col):
+        """
+        An expression that adds/replaces field in StructType by name.
+
+        >>> from pyspark.sql import Row, functions
+        >>> df = spark.createDataFrame([Row(a=Row(b=1, c=2))])
+        >>> df.withColumn('a', df['a'].withField('b', 
functions.lit(3))).select('a.b').show()
+        +---+
+        |  b|
+        +---+
+        |  3|
+        +---+
+        >>> df.withColumn('a', df['a'].withField('d', 
functions.lit(4))).select('a.d').show()
+        +---+
+        |  d|
+        +---+
+        |  4|
+        +---+
+        """
+        if not isinstance(col, Column):
+            raise TypeError("col should be a Column")
+

Review comment:
       Can you check if `fieldName` is a string as well?




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



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

Reply via email to