David Katz Posted November 16, 2022 Share Posted November 16, 2022 At the start of my python data function, I validate the input. If the input is not valid, what is the best way to return to spotfire immediately? Link to comment Share on other sites More sharing options...
Gaia Paolini Posted November 17, 2022 Share Posted November 17, 2022 What I tend to do is:create an 'empty_return' function to call if the input is invalid or there is an early terminationthis function returns exactly the same output parameters as needed, but empty versions of themI add a message output string to the output parameters, so it can be saved in a document property and displayed.Other very useful tips on Python data functions in Spotfire in this Community article:https://community.spotfire.com/s/article/Tips-and-Tricks-for-Working-with-Python-in-SpotfireSimple example: I put the main code in a function so it could be exited early in different places if needed.In this case there is an integer input parameter my_parm and three output parameters: two data frames and a message string.import pandas as pdimport numpy as np def empty_return(msg): df1=pd.DataFrame({'errcol':[np.nan]}) df2=pd.DataFrame({'errcol':[np.nan]}) return (df1,df2,msg) def main(parm): if parm==0: return empty_return('parameter was zero') #otherwise normal execution aa=[1,2,3] bb=['A','B','C'] cc=['a','b','c'] df1=pd.DataFrame({'col1':aa,'col2':bb}) df2=pd.DataFrame({'col1':aa,'col2':cc}) message='all good' return (df1,df2,message) df1,df2,message=main(my_parm) Link to comment Share on other sites More sharing options...
David Katz Posted November 17, 2022 Author Share Posted November 17, 2022 Thanks Gaia. This is a good solution. I was hesitant to use it because my data function has a long list of parameters, and I was trying to avoid this: main(x,y,z,a,b,c...) But your endorsement of 'main' led me to consider this - use the tip in the link you provided to load the Spotfire parameters directly into main(): def main(debug): if debug = True: main(False) within SF main(True) to debug in emacs or... Does this make sense to you? *David Katz*, TIBCO Data Science 1.541.324.7417 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now