Dimension objects¶
-
class
cr.cube.dimension.
Dimension
(dimension_dict, dimension_type, dimension_transforms=None)[source]¶ Represents one dimension of a cube response.
Each dimension represents one of the variables in a cube response. For example, a query to cross-tabulate snack-food preference against region will have two variables (snack-food preference and region) and will produce a two-dimensional (2D) cube response. That cube will have two of these dimension objects, which are accessed using
CrunchCube.dimensions
.-
all_elements
[source]¶ Elements object providing cats or subvars of this dimension.
Elements in this sequence appear in cube-result order.
-
apply_transforms
(dimension_transforms) → cr.cube.dimension.Dimension[source]¶ Return a new Dimension object with dimension_transforms applied.
The new dimension object is the same as this one in all other respects.
-
element_aliases
[source]¶ tuple of string element-aliases for each valid element in this dimension.
Element-aliases appear in the order defined in the cube-result.
-
element_ids
[source]¶ tuple of int element-id for each valid element in this dimension.
Element-ids appear in the order defined in the cube-result.
-
element_labels
[source]¶ tuple of string element-labels for each valid element in this dimension.
Element-labels appear in the order defined in the cube-result.
tuple of int element-idx for each hidden valid element in this dimension.
An element is hidden when a “hide” transform is applied to it in its transforms dict.
-
insertion_ids
[source]¶ tuple of int insertion-id for each insertion in this dimension.
Insertion-ids appear in the order insertions are defined in the dimension.
-
numeric_values
[source]¶ tuple of numeric values for valid elements of this dimension.
Each category of a categorical variable can be assigned a numeric value. For example, one might assign like=1, dislike=-1, neutral=0. These numeric mappings allow quantitative operations (such as mean) to be applied to what now forms a scale (in this example, a scale of preference).
The numeric values appear in the same order as the categories/elements of this dimension. Each element is represented by a value, but an element with no numeric value appears as np.nan in the returned list.
-
subtotal_aliases
[source]¶ tuple of string element-aliases for each subtotal in this dimension.
Element-aliases appear in the order defined in the cube-result.
-
subtotal_labels
[source]¶ tuple of string element-labels for each subtotal in this dimension.
Element-labels appear in the order defined in the cube-result.
-
subtotals
[source]¶ _Subtotals sequence object for this dimension.
Each item in the sequence is a _Subtotal object specifying a subtotal, including its addends and anchor.
-
subtotals_in_payload_order
[source]¶ _Subtotals sequence object for this dimension respecting the payload order.
Each item in the sequence is a _Subtotal object specifying a subtotal, including its addends and anchor.
-
translate_element_id
(_id) → Optional[str][source]¶ Optional string that is the translation of various ids to subvariable alias
This is needed for the opposing dimension’s sort by opposing element, because when creating a dimension, we don’t have access to the other dimension’s ids to transform it. Therefore, the id for opposing element sort by value transforms is not translated at creation time.
- If dimension is not a subvariables dimension, return the _id.
- If id matches an alias, then just use it.
- If id matches a subvariable id, translate to corresponding alias.
- If id matches an element id, translate to corresponding alias.
- If id can be parsed to int and matches an element id, translate to alias.
- If id is int (or can be parsed to int) and can be used as index (eg in range 0-# of elements), use _id’th alias.
- If all of these fail, return None.
-