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.

alias[source]

Return the alias for the dimension if it exists, None otherwise.

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.

description[source]

str description of this dimension.

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.

hidden_idxs[source]

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.

name[source]

str name of this dimension, the empty string (“”) if not specified.

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.

order_spec[source]

_OrderSpec proxy object for dimension.transforms.order dict from payload.

prune[source]

True if empty elements should be automatically hidden on this dimension.

selected_categories[source]

List of selected categories specified for this dimension.

shape[source]

int count of all elements in this dimension, both valid and missing.

smoothing_dict[source]

Optional dict of smoothing specifications.

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.

  1. If dimension is not a subvariables dimension, return the _id.
  2. If id matches an alias, then just use it.
  3. If id matches a subvariable id, translate to corresponding alias.
  4. If id matches an element id, translate to corresponding alias.
  5. If id can be parsed to int and matches an element id, translate to alias.
  6. 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.
  7. If all of these fail, return None.
valid_elements[source]

Elements object providing access to non-missing elements.

Any categories or subvariables representing missing data are excluded from the collection; this sequence represents a subset of that provided by .all_elements.