model_element
ModelElement(data, **kwargs)
Bases: ABC
Source code in pyoframe/model_element.py
dimensions
property
The names of the data's dimensions.
Examples:
dimensions_unsafe
property
Same as dimensions
but returns an empty list if there are no dimensions instead of None.
When unsure, use dimensions
instead since the type checker forces users to handle the None case (no dimensions).
shape
property
The number of indices in each dimension.
Examples:
ModelElementWithId(data, **kwargs)
Bases: ModelElement
Provides a method that assigns a unique ID to each row in a DataFrame. IDs start at 1 and go up consecutively. No zero ID is assigned since it is reserved for the constant variable term. IDs are only unique for the subclass since different subclasses have different counters.
Source code in pyoframe/model_element.py
SupportPolarsMethodMixin
Bases: ABC
_new(data)
abstractmethod
Used to create a new instance of the same class with the given data (for e.g. on .rename(), .with_columns(), etc.).
pick(**kwargs)
Filters elements by the given criteria and then drops the filtered dimensions.
Examples:
>>> m = pf.Model()
>>> m.v = pf.Variable([{"hour": ["00:00", "06:00", "12:00", "18:00"]}, {"city": ["Toronto", "Berlin", "Paris"]}])
>>> m.v.pick(hour="06:00")
<Expression size=3 dimensions={'city': 3} terms=3>
[Toronto]: v[06:00,Toronto]
[Berlin]: v[06:00,Berlin]
[Paris]: v[06:00,Paris]
>>> m.v.pick(hour="06:00", city="Toronto")
<Expression size=1 dimensions={} terms=1>
v[06:00,Toronto]
Source code in pyoframe/model_element.py
_support_polars_method(method_name)
Wrapper to add a method to ModelElement that simply calls the underlying Polars method on the data attribute.