model_element
Classes:
Name | Description |
---|---|
ModelElement |
|
ModelElementWithId |
Provides a method that assigns a unique ID to each row in a DataFrame. |
SupportPolarsMethodMixin |
|
ModelElement(data, **kwargs)
Bases: ABC
Methods:
Name | Description |
---|---|
__len__ |
|
on_add_to_model |
|
Attributes:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
|
dimensions |
Optional[List[str]]
|
The names of the data's dimensions. |
dimensions_unsafe |
List[str]
|
Same as |
friendly_name |
str
|
|
name |
|
|
shape |
Dict[str, int]
|
The number of indices in each dimension. |
Source code in pyoframe/model_element.py
data
property
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).
friendly_name
property
name = None
instance-attribute
shape
property
The number of indices in each dimension.
Examples:
__len__()
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.
Methods:
Name | Description |
---|---|
get_id_column_name |
Returns the name of the column containing the IDs. |
Source code in pyoframe/model_element.py
SupportPolarsMethodMixin
Bases: ABC
Methods:
Name | Description |
---|---|
pick |
Filters elements by the given criteria and then drops the filtered dimensions. |
Attributes:
Name | Type | Description |
---|---|---|
data |
|
|
estimated_size |
|
|
filter |
|
|
rename |
|
|
with_columns |
|
data
abstractmethod
property
estimated_size = _support_polars_method('estimated_size')
class-attribute
instance-attribute
filter = _support_polars_method('filter')
class-attribute
instance-attribute
rename = _support_polars_method('rename')
class-attribute
instance-attribute
with_columns = _support_polars_method('with_columns')
class-attribute
instance-attribute
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]