Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support keyword-only arguments #116

Merged
merged 22 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/sciline/_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"""Callable that can be converted to a provider."""

ProviderKind = Literal[
'function', 'parameter', 'series', 'table', 'sentinel', 'unsatisfied'
'function', 'parameter', 'series', 'table_label', 'sentinel', 'unsatisfied'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why label? I thought that would refer to columns, or it at least feels unclear?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is what it's called in the code:

Provider.table_label(label),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but shouldn't that be renamed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know. Pipeline seems to use 'label' and 'index' interchangeably for tables. So we could rename it to index?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is two different things. If you rename it to index it would mean an entry of the index column:

  • A param table has an "index" column, and one or more data columns. Columns are labeled using a type.
  • The index is a bit like an index in a pandas.DataFrame (and it also has a column label, the type of the index).
  • A cell in the table is identified using an index value, i.e., row index (an index, in the alternate meaning of the word index, i.e., an entry of the index column) and a column label.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You renamed the method to table_cell, but here it is still table_label.

]
"""Identifies the kind of a provider, most are used internally."""

Expand Down Expand Up @@ -80,14 +80,14 @@ def parameter(cls, param: Any) -> Provider:
)

@classmethod
def table_row(cls, param: Any) -> Provider:
def table_label(cls, param: Any) -> Provider:
"""Construct a provider that returns the label for a table row."""
return cls(
func=lambda: param,
arg_spec=ArgSpec.null(),
kind='table',
kind='table_label',
location=ProviderLocation(
name=f'table_row({type(param).__name__})', module=_module_name(param)
name=f'table_label({type(param).__name__})', module=_module_name(param)
),
)

Expand Down
2 changes: 1 addition & 1 deletion src/sciline/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _provider_source(
p: Tuple[Key, Tuple[Union[Key, TypeVar], ...], List[Provider]]
) -> str:
key, _, (v, *rest) = p
if v.kind == 'table':
if v.kind == 'table_label':
# This is always the case, but mypy complains
if isinstance(key, Item):
return escape(
Expand Down
4 changes: 2 additions & 2 deletions src/sciline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ def set_param_table(self, params: ParamTable) -> None:
for index, label in zip(params.index, values):
self._set_provider(
Item((Label(tp=params.row_dim, index=index),), param_name),
Provider.table_row(label),
Provider.table_label(label),
)
for index, label in zip(params.index, params.index):
self._set_provider(
Item((Label(tp=params.row_dim, index=index),), params.row_dim),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary, but could this clumsy key setup be absorbed into the Provider class, similar to the function case? Provider.table would obviously need more arguments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you store the key in the provider? This would duplicate the key as we still need it in the graph / pipeline.

Provider.table_row(label),
Provider.table_label(label),
)

def del_param_table(self, row_dim: type) -> None:
Expand Down
Loading