Links

Variable

class Variable

Variables represent the "columns" in tables (and uploads), and have certain metadata as well as detailed univariate summary statistics associated with them. Use this class to interface with variables and their metadata.

Attributes

properties: A dict containing the API resource representation of the variable. This will only be populated after certain methods are called (see below), and will otherwise be None.

Methods

get(wait_for_statistics=False)

Fetches the variable, after which variable.properties will contain a dict with entries corresponding to the properties on the variable resource definition. Will raise an error if the variable does not exist.
Parameters:
  • wait_for_statistics (bool, default False): if True, will wait for summary statistics on the variable to be fully populated before returning.
Returns: self

exists()

Check whether the variable exists.
Returns: boolean

update(*, label, description, value_labels)

Update metadata attributes on the variable
Parameters:
  • label (str): A human-readable label for the variable. Must be <= 256 characters. Provide an empty string to unset.
  • description (str): A longer description of the variable. Must be <= 5000 characters. Provide an empty string to unset.
  • value_labels (dict): A dictionary of value: label pairs, representing human readable labels for coded values on this variable. Provide an empty dict to unset.

Examples

table = redivis.organization("Demo").dataset("Iris species").table("Iris")
variable = table.variable("sepalLengthCm")
variable.exists() # -> True
variable.get(wait_for_statistics=True)
print(variable.properties)
{
"kind": "variable",
... (see variable resource definition)
"statistics": {
"status": "completed",
"count": 150,
"numDistinct": 35,
"min": 4.3,
"max": 7.9,
"mean": 5.8433333333333355,
"approxMedian": 0.8280661279778625
}
}
Last modified 25d ago