liangz1 commented on a change in pull request #34021:
URL: https://github.com/apache/spark/pull/34021#discussion_r710147710



##########
File path: python/pyspark/sql/dataframe.py
##########
@@ -2536,6 +2536,28 @@ def withColumnRenamed(self, existing, new):
         """
         return DataFrame(self._jdf.withColumnRenamed(existing, new), 
self.sql_ctx)
 
+    def withMetadata(self, columnName, metadata):
+        """Returns a new :class:`DataFrame` by updating an existing column 
with metadata.
+
+        .. versionadded:: 3.3.0
+
+        Parameters
+        ----------
+        columnName : str
+            string, name of the existing column to update the metadata.
+        metadata : dict
+            dict, new metadata to be assigned to df.schema[columnName].metadata
+
+        Examples
+        --------
+        >>> df_meta = df.withMetadata('age', {'foo': 'bar'})
+        >>> df_meta.schema['age'].metadata
+        {'foo': 'bar'}
+        """
+        if not isinstance(metadata, dict):
+            raise TypeError("metadata should be a dict")
+        return DataFrame(self._jdf.withMetadata(columnName, metadata), 
self.sql_ctx)

Review comment:
       Nice catch! I updated the conversion.




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