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

Standardize parameter mapping APIs #4386

Merged
merged 23 commits into from
Feb 6, 2023
Merged

Standardize parameter mapping APIs #4386

merged 23 commits into from
Feb 6, 2023

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Feb 3, 2023

Over time we accumulated a bunch of workaround for mapping parameters to properties. Specifically we had the _rename dictionary used for mapping from parameter to property names, then we had various _init_params and _get_properties methods used to provide parameters to initialize and update properties on the underlying bokeh model. This PR attempts to rationalize this a bit:

  • _rename consistently used to declare parameter mapping (i.e. avoid manual workarounds for this)
  • Bokeh models are now always initialized by calling _get_properties which itself calls _init_params and then transforms those parameters with _process_param_change, ensuring that as much logic for mapping from Panel parameters to Bokeh properties is encapsulated in this method.
  • Introduce a ModelPane baseclass for panes that very simply map to an underlying bokeh model and apply some transformations to parameters.

@hoxbro
Copy link
Member

hoxbro commented Feb 6, 2023

I would like to see all the type changes be made in another PR.

@philippjfr
Copy link
Member Author

Fair, just to clarify that is for review purposes, to avoid merge conflicts or something else?

@hoxbro
Copy link
Member

hoxbro commented Feb 6, 2023

Review purposes and to be able to look at the PR in the future if needed.

@philippjfr
Copy link
Member Author

Done, please review in that case 😄

@codecov
Copy link

codecov bot commented Feb 6, 2023

Codecov Report

Merging #4386 (ec82cd1) into branch-1.0 (c0a3902) will decrease coverage by 0.07%.
The diff coverage is 70.16%.

@@              Coverage Diff               @@
##           branch-1.0    #4386      +/-   ##
==============================================
- Coverage       73.53%   73.47%   -0.07%     
==============================================
  Files             237      238       +1     
  Lines           34527    34857     +330     
==============================================
+ Hits            25390    25611     +221     
- Misses           9137     9246     +109     
Flag Coverage Δ
unitexamples-tests 73.47% <70.16%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
panel/io/jupyter_executor.py 0.00% <0.00%> (ø)
panel/io/jupyter_server_extension.py 0.00% <0.00%> (ø)
panel/io/liveness.py 25.00% <ø> (-1.09%) ⬇️
panel/io/mime_render.py 83.11% <ø> (ø)
panel/layout/gridstack.py 53.33% <ø> (-1.51%) ⬇️
panel/layout/spacer.py 74.07% <0.00%> (ø)
panel/models/__init__.py 100.00% <ø> (ø)
panel/models/plotly.py 93.54% <ø> (ø)
panel/template/material/__init__.py 100.00% <ø> (ø)
panel/template/react/__init__.py 100.00% <ø> (ø)
... and 180 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@philippjfr
Copy link
Member Author

Want to make progress elsewhere (and merge this into the UI test PR) so I'll probably go ahead and merge. This is extremely difficult to review but if you do find the time/desire to do so I'll apply any fixes in a new PR.

@philippjfr philippjfr merged commit 1f34314 into branch-1.0 Feb 6, 2023
@philippjfr philippjfr deleted the pane_api branch February 6, 2023 20:55
Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

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

Have added some comment.

Add some point I think we should use list/tuple/dict instead of List/Tuple/Dict. This can be done automatic with pyupgrade or ruff.

@@ -616,6 +625,8 @@ class ListPanel(ListLike, Panel):
Whether to add scrollbars if the content overflows the size
of the container.""")

_rename: ClassVar[Mapping[str, str | None]] = {'scroll': None}
Copy link
Member

Choose a reason for hiding this comment

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

Mapping[str, str | None] is used a lot maybe we should make it a type alias?

@@ -30,7 +33,7 @@ class Alert(Markdown):

priority: ClassVar[float | bool | None] = 0

_rename: ClassVar[Mapping[str, str | None]] = dict(Markdown._rename, alert_type=None)
_rename: ClassVar[Mapping[str, str | None]] = {'alert_type': None}
Copy link
Member

Choose a reason for hiding this comment

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

Why was Markdown._rename removed?

Defines the PaneBase class defining the API for panes which convert
objects to a visual representation expressed as a bokeh model.
Defines base classes for Pane components which allow wrapping a Python
object transforming it into a Bokeh model that can be rendered.
Copy link
Member

Choose a reason for hiding this comment

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

Would probably update with:
...object and transforming...
...that can be rendered in the browser.

@@ -1651,6 +1683,7 @@ def _get_template(self) -> Tuple[str, List[str], Mapping[str, List[Tuple[str, Li
html = html.replace('${%s}' % child_name, '')
return html, parser.nodes, p_attrs

@property
def _linked_properties(self) -> List[str]:
Copy link
Member

Choose a reason for hiding this comment

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

Should be returning tuple type.

@@ -274,7 +268,7 @@ class Number(ValueIndicator):
title_size = param.String(default='18pt', doc="""
The size of the title given by the name.""")

_rename: ClassVar[Mapping[str, str | None]] = {}
_rename: ClassVar[Mapping[str, str | None]] = {'name': 'name'}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow this rename... Is it because the parent class rename name?

philippjfr added a commit that referenced this pull request Feb 8, 2023
philippjfr added a commit that referenced this pull request Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants