cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
eranraz100
Level I

Python script depot - getting a KeyError when inputing key values

I got a python score script generated by the JMP depot ,

When I send a dict of values (taken from a json file)  to the score formula, I t ends up with KeyError (as if the key doesn’t exist , but it is )Could that be  a backspace issue?

I  attached the JMP file and the json file

thanks

Eran

 

 

 

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
nascif_jmp
Level VI

Re: Python script depot - getting a KeyError when inputing key values

Hi @eranraz100,

Glad to see you deploying our models to production!

 

The KeyError is about a string used as key in the input dictionary, that in turn is generated from the JMP column names used as input in your model. JMP supports spaces in column names, and the strings used as keys in the generated Python code also have embedded spaces:

def getInputMetadata():
    return {
        # ...
        u"SURFACE FINISH CS": "str",
	}

It looks like the process that is generating the JSON input data is replacing these spaces with underscores:

{
  "SURFACE_FINISH_CS":"FULL_HGLD",
}

I hope this is easy to fix on the JSON generation side, but if not, changing the column names to replace the spaces with underscores and regenerating the model would do the trick.

 

View solution in original post

eranraz100
Level I

Re: Python script depot - getting a KeyError when inputing key values

Hi, thank you  for the quick response

as you mention , I used a function to alter the json generated  - and it worked.

you can mark the issue as solved

thanks again

Eran

View solution in original post

nascif_jmp
Level VI

Re: Python script depot - getting a KeyError when inputing key values

Hi again @eranraz100,

Welcome to the JMP Community, looks like you just joined.

I am curious about your usage of our Python scoring code - you are the first customer who asked about using JSON as input. 

I always thought this would be a prime usage scenario as it makes it easier for our models to consume data from web-based processes.

 

For example, this is a web application created for a JMP Discovery 2017 conference tutorial.

The frontend is a static app based on Leaflet and the backend is one of our models exported to Python and running on AWS Lambda.

Are you doing something along those lines?

 

 

View solution in original post

4 REPLIES 4
nascif_jmp
Level VI

Re: Python script depot - getting a KeyError when inputing key values

Hi @eranraz100,

Glad to see you deploying our models to production!

 

The KeyError is about a string used as key in the input dictionary, that in turn is generated from the JMP column names used as input in your model. JMP supports spaces in column names, and the strings used as keys in the generated Python code also have embedded spaces:

def getInputMetadata():
    return {
        # ...
        u"SURFACE FINISH CS": "str",
	}

It looks like the process that is generating the JSON input data is replacing these spaces with underscores:

{
  "SURFACE_FINISH_CS":"FULL_HGLD",
}

I hope this is easy to fix on the JSON generation side, but if not, changing the column names to replace the spaces with underscores and regenerating the model would do the trick.

 

eranraz100
Level I

Re: Python script depot - getting a KeyError when inputing key values

Hi, thank you  for the quick response

as you mention , I used a function to alter the json generated  - and it worked.

you can mark the issue as solved

thanks again

Eran

nascif_jmp
Level VI

Re: Python script depot - getting a KeyError when inputing key values

Hi again @eranraz100,

Welcome to the JMP Community, looks like you just joined.

I am curious about your usage of our Python scoring code - you are the first customer who asked about using JSON as input. 

I always thought this would be a prime usage scenario as it makes it easier for our models to consume data from web-based processes.

 

For example, this is a web application created for a JMP Discovery 2017 conference tutorial.

The frontend is a static app based on Leaflet and the backend is one of our models exported to Python and running on AWS Lambda.

Are you doing something along those lines?

 

 

eranraz1
Level II

Re: Python script depot - getting a KeyError when inputing key values

Hi, yes that’s the sort of solution we are trying to implement

I’m using Flask web-framework as REST API, the purpose is to let SAP consume that API during price quotation- calculation  

The API does some data validation and conversion, and then address the score function with parameters

 

thanks for your help and the useful data you attached 

cheers

Eran