cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with extending DataFrame-object with custom method in DBR 14.0

hanspetter
New Contributor III

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 "TypeError: 'Column' object is not callable".

 

 

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

 

 

 Is this expected behaviour?

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group