<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problems with extending DataFrame-object with custom method in DBR 14.0 in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/problems-with-extending-dataframe-object-with-custom-method-in/m-p/45656#M27963</link>
    <description>&lt;P&gt;I noticed that extending the DataFrame object with a custom method does not work in DBR 14.0 This works fine in when using DBR 13.3. The below code throws a "&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;&lt;SPAN&gt;: 'Column' object is not callable&lt;/SPAN&gt;".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import col,lit
from pyspark.sql.dataframe import DataFrame

def custom_method(df):
  new_df = df.withColumn("new_column", lit(1))
  return new_df

setattr(DataFrame, "custom_method", custom_method)
#Also tried: DataFrame.custom_method = custom_method

d = [{'empid': 1, 'name': 'Test'}]

my_df = spark.createDataFrame(d)

my_df = my_df.custom_method()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is this expected behaviour?&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2023 12:12:27 GMT</pubDate>
    <dc:creator>hanspetter</dc:creator>
    <dc:date>2023-09-22T12:12:27Z</dc:date>
    <item>
      <title>Problems with extending DataFrame-object with custom method in DBR 14.0</title>
      <link>https://community.databricks.com/t5/data-engineering/problems-with-extending-dataframe-object-with-custom-method-in/m-p/45656#M27963</link>
      <description>&lt;P&gt;I noticed that extending the DataFrame object with a custom method does not work in DBR 14.0 This works fine in when using DBR 13.3. The below code throws a "&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;&lt;SPAN&gt;: 'Column' object is not callable&lt;/SPAN&gt;".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import col,lit
from pyspark.sql.dataframe import DataFrame

def custom_method(df):
  new_df = df.withColumn("new_column", lit(1))
  return new_df

setattr(DataFrame, "custom_method", custom_method)
#Also tried: DataFrame.custom_method = custom_method

d = [{'empid': 1, 'name': 'Test'}]

my_df = spark.createDataFrame(d)

my_df = my_df.custom_method()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Is this expected behaviour?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 12:12:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/problems-with-extending-dataframe-object-with-custom-method-in/m-p/45656#M27963</guid>
      <dc:creator>hanspetter</dc:creator>
      <dc:date>2023-09-22T12:12:27Z</dc:date>
    </item>
  </channel>
</rss>

