cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar

Empty/Strange Python object after retrieving via Application Builder Script

Hi everyone, 

 

(JMP 17 Pro user) I am encountering a strange issue when attempting to pass data table objects to Python and retrieve them back into JSL, specifically while using Application Builder. 

 

As this is the first time I've used Application Builder, I wrote out a rough draft of the behavior I wanted in the app via a standard JSL script (for context, the goal is an application that allows user to select directory/file, then let JMP generate a graph for analysis). The behavior works in a standard JSL script, but does not work within the Application Builder. 

 

Here's my standalone (non-Application Builder) script:

// Initialize Python within JMP
PyConnect = Python Connect();

Names Default to Here( 1 );

// Allow user to manually pick directory and file
directory = Pick Directory ("Select a directory.");
chosen_file = Pick File("Select a file", directory);

// Open the selected file, then send to Python
dt1 = Open(chosen_file, Table Contains Column Headers(0));
Python Send(dt1);

// Close the dirty data table to save space/resources
Close(dt1, NoSave);

show(dt1, "first");

// Clean the table by removing all references to "#"
Python Submit("\[

dt1 = dt1[~dt1["Column 1"].str.contains("#")]

]\");

// Retrieve the processed table from Python and open in JMP
// Terminate Python connection
dt1 = Python Get(dt1);
Python Term();

show(dt1, "second");

And the output for this script: 

dt1 = DataTable("D424TUZ0.Inspec Meas 01");
"first";

dt1 = DataTable("dt1");
"second";

(NOT WORKING) Here's my Application Builder script:

executePress=Function({thisBox}, {Default Local},
	// This function is called when the button is pressed
	py = Python Connect();

	dt1 = Open(::file, Table Contains Column Headers(0));
	
	Close(dt1, NoSave);
	
	show(dt1, "first");
	
	// Clean the table by removing all references to "#"
	Python Submit("\[

	dt1 = dt1[~dt1["Column 1"].str.contains("#")]

	]\");
	
	dt1 = Python Get(dt1);
	Python Term();
	
	show(dt1, "second");
);

and the troubling output:

dt1 = DataTable("D424TUZ0.Inspec Meas 01");
"first";
/**********/


	dt1 = dt1[~dt1["Column 1"].str.contains("#")]

	
/**********/
dt1 = .;
"second";

TLDR: in my standalone script, after retrieving my data table back from cleaning in Python via dt1 = Python Get(dt1);, I get back an object as dt1 = DataTable("dt1");. However in JMP Application Builder script, I get dt1 = .; (which to me indicates that the object doesn't exist?). 

 

I first recognized this when I attempted to use dt1 << New Data Window; and reading this thread made me realize that I likely am not working with an object at all: https://community.jmp.com/t5/Discussions/Error-in-running-script-Send-Expects-Scriptable-Object-in-a...

 

Apologies for the long post. It's a strange error, and thank you to anybody in advance for your help on this problem!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Empty/Strange Python object after retrieving via Application Builder Script

I don't see in your Application Builder script any Python Send(dt1); 

 

Also note, that JMP 18 changes what happens with a Python Send(dt).  In JMP 18 and beyond, you get a jmp.DataTable object instead of a pandas.DataFrame.  And that DataTable object is no longer a copy of the data but live access to the data table, you can do processing in Python directly on the live table.  See the Scripting Index in JMP 18 for examples of the Python APIs supported via the import jmp package. 

 

If you need to go from jmp.DataTable to pandas.DataFrame there are several examples in the $SAMPLE_SCRIPTS/Python directory.  dt2pandas.py does exactly what JMP 14-17 did, save the DataTable to disk as a temporary CSV file, the tell pandas to read_csv() on the file.  JMP2pandas.py is an example script showing how to use the capabilities of the jmp.DataTable object and create a pandas.DataFrame in memory.

 

Python Get( dt ) recognizes the new jmp.DataTable object, while Python Get( df ) will recognize the DataFrame and import using CSV the same as JMP 14-17

View solution in original post

2 REPLIES 2

Re: Empty/Strange Python object after retrieving via Application Builder Script

I don't see in your Application Builder script any Python Send(dt1); 

 

Also note, that JMP 18 changes what happens with a Python Send(dt).  In JMP 18 and beyond, you get a jmp.DataTable object instead of a pandas.DataFrame.  And that DataTable object is no longer a copy of the data but live access to the data table, you can do processing in Python directly on the live table.  See the Scripting Index in JMP 18 for examples of the Python APIs supported via the import jmp package. 

 

If you need to go from jmp.DataTable to pandas.DataFrame there are several examples in the $SAMPLE_SCRIPTS/Python directory.  dt2pandas.py does exactly what JMP 14-17 did, save the DataTable to disk as a temporary CSV file, the tell pandas to read_csv() on the file.  JMP2pandas.py is an example script showing how to use the capabilities of the jmp.DataTable object and create a pandas.DataFrame in memory.

 

Python Get( dt ) recognizes the new jmp.DataTable object, while Python Get( df ) will recognize the DataFrame and import using CSV the same as JMP 14-17

Re: Empty/Strange Python object after retrieving via Application Builder Script

Thank you so much for your detailed solution, this was very helpful. I can't believe I missed something so small.