cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my Notebook fails if I try to load a function from another Notebook in Repos in Databricks

shubhamb
New Contributor III

My function in func.py

def lower_events(df):
 return df.withColumn("event",f.lower(f.col("event")))

My main notebook

import pyspark.sql.functions as f
from pyspark.sql.functions import udf, col, lower
import sys
 
sys.path.append("..")
from folder.func.  import   lower_events
#from folder  import   func
 
df_clean = lower_events(df)

I am getting this error

NameError: name 'f' is not defined

4 REPLIES 4

-werners-
Esteemed Contributor III

@Shubham Biswas​, so func.py is a plain Python file, not a Databricks notebook?

Can you also check the following topic?

https://community.databricks.com/s/question/0D53f00001mUyh2CAC/limitations-with-udfs-wrapping-module...

Kaniz
Community Manager
Community Manager

Hi @Shubham Biswas​ , Just a friendly follow-up. Do you still need help, or @Werner Stinckens​ 's response help you to find the solution? Please let us know.

Kaniz
Community Manager
Community Manager

Hi @Shubham Biswas​ ​, We haven’t heard from you on the last response from @Werner Stinckens​ , and I was checking back to see if you have a resolution yet. If you have any solution, please do share that with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

shubhamb
New Contributor III
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.