BaseOperableBlock
Bases: BaseBlock
Any object that can be converted into an expression.
Methods:
Name | Description |
---|---|
add_dim |
Deprecated, use |
drop_extras |
Indicates that labels not present in the other expression should be discarded during addition, subtraction, or constraint creation. |
drop_unmatched |
Deprecated, use |
filter |
Creates a copy of the object containing only a subset of the original rows. |
keep_extras |
Indicates that labels not present in the other expression should be kept during addition, subtraction, or constraint creation. |
keep_unmatched |
Deprecated, use |
map |
Converts the object to an expression (see |
over |
Indicates that the expression can be broadcasted over the given dimensions during addition and subtraction. |
pick |
Filters elements by the given criteria and then drops the filtered dimensions. |
raise_extras |
Indicates that labels not present in the other expression should raise an error during addition, subtraction, or constraint creation. |
rename |
Renames one or several of the object's dimensions. |
sum |
Converts the object to an expression (see |
sum_by |
Converts the object to an expression (see |
to_expr |
Converts the object to a Pyoframe Expression. |
with_columns |
Creates a new object with modified columns. |
Source code in pyoframe/_core.py
add_dim(*dims: str)
Deprecated, use over
instead.
Source code in pyoframe/_core.py
drop_extras()
Indicates that labels not present in the other expression should be discarded during addition, subtraction, or constraint creation.
Learn more about addition modifiers.
See Also
Source code in pyoframe/_core.py
drop_unmatched()
Deprecated, use drop_extras
instead.
Source code in pyoframe/_core.py
filter(*args, **kwargs)
Creates a copy of the object containing only a subset of the original rows.
Takes the same arguments as polars.DataFrame.filter
.
See Also
Expression.pick
or Variable.pick
if you wish to drop the filtered
column in the process.
Source code in pyoframe/_core.py
keep_extras()
Indicates that labels not present in the other expression should be kept during addition, subtraction, or constraint creation.
Learn more about addition modifiers.
See Also
Source code in pyoframe/_core.py
keep_unmatched()
Deprecated, use keep_extras
instead.
Source code in pyoframe/_core.py
map(*args, **kwargs)
Converts the object to an expression (see .to_expr()
) and then applies Expression.map
.
over(*dims: str)
Indicates that the expression can be broadcasted over the given dimensions during addition and subtraction.
Source code in pyoframe/_core.py
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 height=3 terms=3 type=linear>
┌─────────┬──────────────────┐
│ city ┆ expression │
│ (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 terms=1 type=linear>
v[06:00,Toronto]
See Also
Expression.filter
or Variable.filter
if you don't wish to drop the filtered column.
Source code in pyoframe/_core.py
raise_extras()
Indicates that labels not present in the other expression should raise an error during addition, subtraction, or constraint creation.
This is the default behavior and, as such, this addition modifier should only be used in the rare cases where you want to override a previous use of keep_extras()
or drop_extras()
.
Learn more about addition modifiers.
See Also
keep_extras
and drop_extras
.
Source code in pyoframe/_core.py
rename(*args, **kwargs)
Renames one or several of the object's dimensions.
Takes the same arguments as polars.DataFrame.rename
.
See the portfolio optimization example for a usage example.
Examples:
>>> m = pf.Model()
>>> m.v = pf.Variable(
... {"hour": ["00:00", "06:00", "12:00", "18:00"]},
... {"city": ["Toronto", "Berlin", "Paris"]},
... )
>>> m.v
<Variable 'v' height=12>
┌───────┬─────────┬──────────────────┐
│ hour ┆ city ┆ variable │
│ (4) ┆ (3) ┆ │
╞═══════╪═════════╪══════════════════╡
│ 00:00 ┆ Toronto ┆ v[00:00,Toronto] │
│ 00:00 ┆ Berlin ┆ v[00:00,Berlin] │
│ 00:00 ┆ Paris ┆ v[00:00,Paris] │
│ 06:00 ┆ Toronto ┆ v[06:00,Toronto] │
│ 06:00 ┆ Berlin ┆ v[06:00,Berlin] │
│ … ┆ … ┆ … │
│ 12:00 ┆ Berlin ┆ v[12:00,Berlin] │
│ 12:00 ┆ Paris ┆ v[12:00,Paris] │
│ 18:00 ┆ Toronto ┆ v[18:00,Toronto] │
│ 18:00 ┆ Berlin ┆ v[18:00,Berlin] │
│ 18:00 ┆ Paris ┆ v[18:00,Paris] │
└───────┴─────────┴──────────────────┘
>>> m.v.rename({"city": "location"})
<Expression height=12 terms=12 type=linear>
┌───────┬──────────┬──────────────────┐
│ hour ┆ location ┆ expression │
│ (4) ┆ (3) ┆ │
╞═══════╪══════════╪══════════════════╡
│ 00:00 ┆ Toronto ┆ v[00:00,Toronto] │
│ 00:00 ┆ Berlin ┆ v[00:00,Berlin] │
│ 00:00 ┆ Paris ┆ v[00:00,Paris] │
│ 06:00 ┆ Toronto ┆ v[06:00,Toronto] │
│ 06:00 ┆ Berlin ┆ v[06:00,Berlin] │
│ … ┆ … ┆ … │
│ 12:00 ┆ Berlin ┆ v[12:00,Berlin] │
│ 12:00 ┆ Paris ┆ v[12:00,Paris] │
│ 18:00 ┆ Toronto ┆ v[18:00,Toronto] │
│ 18:00 ┆ Berlin ┆ v[18:00,Berlin] │
│ 18:00 ┆ Paris ┆ v[18:00,Paris] │
└───────┴──────────┴──────────────────┘
Source code in pyoframe/_core.py
sum(*args, **kwargs)
Converts the object to an expression (see .to_expr()
) and then applies Expression.sum
.
sum_by(*args, **kwargs)
Converts the object to an expression (see .to_expr()
) and then applies Expression.sum_by
.
to_expr() -> Expression
with_columns(*args, **kwargs)
Creates a new object with modified columns.
Takes the same arguments as polars.DataFrame.with_columns
.
Warning
Only use this function if you know what you're doing. It is not recommended to manually modify the columns within a Pyoframe object.
Comments