Project Variables and Data Typing
![indy2005](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar15.png)
Hi
I am a but confused by defininf project variables in DataIku. When I read them back, they are all being typed as string? I understand that I should put all values in quotes when defining the variables, but would have thought there was some type of dynamic typing?
Or do I have to manually do python type conversions on all my variables after reading them in as strings, using get_custom_variables()?
Best Answer
-
Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,211 Dataiker
Hi,
Variables are defined a JSON. Reading project variables will return a dictionary in python for example get_custom_variables().
When you read a specific variable only it would be returned as a string, regardless of this int or boolean in the JSON. So you will have to manually define its type as python does not infer types by default.
The example below today_year was defined as int 2022, if I want to use at int I can simply use int()
In DSS formulas, you can use either use the variables ${var_name} orf parseJSON(variables["var_name]).
https://doc.dataiku.com/dss/latest/formula/index.html#dss-variables
in the DSS formula there is some auto-typing as explained here :
https://doc.dataiku.com/dss/latest/formula/index.html#variables-typing-and-autotyping
For more information on variables please see :
https://knowledge.dataiku.com/latest/courses/o16n/variables/variables101/variables101-summary.html
Answers
-
In the documentation on creating Dataiku Applications, I see the following:
If types are not honored, why the complex JSON structure? When does one use such a structure and when not? Where do the various options listed come from? Also, I would like to allow the users to see a list of options and select multiple options among them. How is this done? Where can I find an example? Thanks.
-
I am about to figure it out. One defines project parameters in the variables area and set up the presentation details in the applications interface.