Skip to content

Dimension class

Bases: Iterable, ABC

Represents a dimension of a cube, mapped to a column in the underlying Pandas dataframe.

df: pd.DataFrame property

Returns the underlying Pandas dataframe the dimension/column refers to.

members: list property

Returns the list of members of the dimension.

member_set: set property

Returns the set of members of the dimension.

column property

Returns the column name in the underlying Pandas dataframe the dimension refers to.

name property

Returns the name (column name in the underlying Pandas dataframe) of the dimension.

dtype property

Returns the Pandas data type of the dimension column.

__init__(df, column, caching=CachingStrategy.LAZY)

Initializes a new Dimension from a Pandas dataframe and a column name.

__getattr__(name)

Dynamically resolves a Filter based on member names from the dimension. This enables a more natural access to the cube data using the Python dot notation.

Member names need to be valid Python identifier/variable name. CubedPandas applies the following rules to resolve member names: - If a member name is also a valid Python identifier, it can be used directly. e.g., Apple - Member name resolving is case-insensitive, e.g., apple will resolve Apple. - White spaces in member names are replaced by underscores, e.g., best_offer will resolve best offer. - Leading numbers in a member name are replaced by underscores, e.g., _2_cute will resolve 2 cute. - Leading and trailing underscores are ignored/removed, e.g., hello will resolve hello. - All other special characters are removed, e.g., 12/4 cars is the same as 124_cars.

  • If the name is not a valid Python identifier (e.g. contains special characters), the slicer method needs to be used to resolve the member name. e.g., 12/4 cars is a valid name for a value

If the name is not a valid Python identifier (e.g. contains special characters), the slicer method needs to be used to resolve the member name. e.g., 12/4 cars is a valid name for a value in a Pandas dataframe column, but not a valid Python identifier/variable name, hence dimension["12/4 cars"] needs to be used to return the member.

Parameters:

  • name

    Name of a member or measure in the cube.

Returns:

  • A Cell object that represents the cube data related to the address.

Samples

cdf = cubed(df) cdf.Online.Apple.cost 50

clear_cache()

Clears the cache of the Dimension.

wildcard_filter(pattern)

Returns a list of members that match the given wildcard pattern.

Parameters:

  • pattern

    A wildcard pattern to filter the dimension members.

Returns:

  • (bool, list)

    A new DimensionFilter object.

count(member)

Returns the number of rows in the underlying dataframe where the dimension column contains the given member.

choice()

Return a random member from the dimension.

See https://docs.python.org/3/library/random.html#random.choice for more information.

Returns:

  • Return a random member from the dimension.

choices(k=1, weights=None, cum_weights=None)

Return a k sized list of members chosen from the dimension (with replacement).

See https://docs.python.org/3/library/random.html#random.choices for more information.

Returns:

  • Return a k sized list of members chosen from the dimension (with replacement).

sample(k=1, counts=None)

Return a k sized list of unique members chosen from the dimension (without replacement).

See https://docs.python.org/3/library/random.html#random.sample for more information.

Returns:

  • Return a k sized list of unique members chosen from the dimension (without replacement).