Skip to content

Commit

Permalink
Replace _ignored_refs with explicit allow_refs (#5565)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Oct 3, 2023
1 parent c0949f4 commit bec9f2f
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 34 deletions.
2 changes: 1 addition & 1 deletion panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from bokeh.document import Document
from bokeh.model import Model
from bokeh.settings import settings as bk_settings
from param.depends import (
from param.display import (
register_display_accessor, unregister_display_accessor,
)
from pyviz_comms import (
Expand Down
4 changes: 1 addition & 3 deletions panel/pane/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,7 @@ class ReplacementPane(PaneBase):

_pane = param.ClassSelector(class_=Viewable, allow_refs=False)

_ignored_refs: ClassVar[Tuple[str]] = ['object', '_pane']

_linked_properties: ClassVar[Tuple[str]] = ()
_linked_properties: ClassVar[Tuple[str,...]] = ()

_rename: ClassVar[Mapping[str, str | None]] = {'_pane': None, 'inplace': None}

Expand Down
4 changes: 1 addition & 3 deletions panel/pane/holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import OrderedDict, defaultdict
from functools import partial
from typing import (
TYPE_CHECKING, Any, ClassVar, Mapping, Optional, Tuple, Type,
TYPE_CHECKING, Any, ClassVar, Mapping, Optional, Type,
)

import param
Expand Down Expand Up @@ -685,8 +685,6 @@ class Interactive(PaneBase):

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

_ignored_refs: ClassVar[Tuple[str]] = ['object']

def __init__(self, object=None, **params):
super().__init__(object, **params)
self._update_layout()
Expand Down
4 changes: 1 addition & 3 deletions panel/pane/ipywidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

from typing import (
TYPE_CHECKING, Any, ClassVar, List, Optional,
TYPE_CHECKING, Any, ClassVar, Optional,
)

import param
Expand Down Expand Up @@ -43,8 +43,6 @@ class IPyWidget(PaneBase):

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

_ignored_refs: ClassVar[List[str]] = ['object']

@classmethod
def applies(cls, obj: Any) -> float | bool | None:
return (hasattr(obj, 'traits') and hasattr(obj, 'get_manager_state') and hasattr(obj, 'comm'))
Expand Down
4 changes: 1 addition & 3 deletions panel/pane/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from contextlib import contextmanager
from io import BytesIO
from typing import (
TYPE_CHECKING, Any, ClassVar, Dict, List, Mapping, Optional,
TYPE_CHECKING, Any, ClassVar, Dict, Mapping, Optional,
)

import param
Expand Down Expand Up @@ -230,8 +230,6 @@ class Matplotlib(Image, IPyWidget):
Automatically adjust the figure size to fit the
subplots and other artist elements.""")

_ignored_refs: ClassVar[List[str]] = []

_rename: ClassVar[Mapping[str, str | None]] = {
'object': 'text', 'interactive': None, 'dpi': None, 'tight': None,
'high_dpi': None, 'format': None, 'encode': None
Expand Down
3 changes: 0 additions & 3 deletions panel/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,6 @@ class ReactiveExpr(PaneBase):

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

# Parameter values which should not be treated like references
_ignored_refs: ClassVar[List[str]] = ['object']

_layouts = {
'left': (Row, ('start', 'center'), True),
'right': (Row, ('end', 'center'), False),
Expand Down
3 changes: 0 additions & 3 deletions panel/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import traceback as tb

from collections import OrderedDict, defaultdict
from typing import ClassVar, Tuple

import param

Expand Down Expand Up @@ -165,8 +164,6 @@ class Pipeline(Viewer):

previous = param.Action(default=lambda x: x.param.trigger('previous'))

_ignored_refs: ClassVar[Tuple[str]] = ('next_parameter', 'ready_parameter')

def __init__(self, stages=[], graph={}, **params):
try:
import holoviews as hv
Expand Down
7 changes: 2 additions & 5 deletions panel/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,6 @@ class Reactive(Syncable, Viewable):
the parameters to other objects.
"""

# Parameter values which should not be treated like references
_ignored_refs: ClassVar[List[str]] = []

_rename: ClassVar[Mapping[str, str | None]] = {
'design': None, 'loading': None
}
Expand All @@ -538,8 +535,8 @@ class Reactive(Syncable, Viewable):

def __init__(self, refs=None, **params):
for name, pobj in self.param.objects('existing').items():
enable_refs = name not in self._ignored_refs
pobj.allow_refs = enable_refs
if name not in self._param__private.explicit_no_refs:
pobj.allow_refs = True
super().__init__(**params)

#----------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions panel/tests/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ def test_reactive_widget_order():

def test_reactive_dataframe_method_chain(dataframe):
dfi = rx(dataframe).groupby('str')[['float']].mean().reset_index()
pd.testing.assert_frame_equal(dfi.rx.resolve(), dataframe.groupby('str')[['float']].mean().reset_index())
pd.testing.assert_frame_equal(dfi.rx.value, dataframe.groupby('str')[['float']].mean().reset_index())

def test_reactive_dataframe_attribute_chain(dataframe):
array = rx(dataframe).str.values.rx.resolve()
array = rx(dataframe).str.values.rx.value
np.testing.assert_array_equal(array, dataframe.str.values)

def test_reactive_dataframe_param_value_method_chain(dataframe):
P = Parameters(string='str')
dfi = rx(dataframe).groupby(P.param.string)[['float']].mean().reset_index()
pd.testing.assert_frame_equal(dfi.rx.resolve(), dataframe.groupby('str')[['float']].mean().reset_index())
pd.testing.assert_frame_equal(dfi.rx.value, dataframe.groupby('str')[['float']].mean().reset_index())
P.string = 'int'
pd.testing.assert_frame_equal(dfi.rx.resolve(), dataframe.groupby('int')[['float']].mean().reset_index())
pd.testing.assert_frame_equal(dfi.rx.value, dataframe.groupby('int')[['float']].mean().reset_index())

def test_reactive_layout_default_with_widgets():
w = IntSlider(value=2, start=1, end=5)
Expand Down
2 changes: 0 additions & 2 deletions panel/widgets/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,6 @@ class Tqdm(Indicator):
write_to_console = param.Boolean(default=False, doc="""
Whether or not to also write to the console.""")

_ignored_refs: ClassVar[List[str]] = ['progress']

_layouts: ClassVar[Dict[Type[Panel], str]] = {Row: 'row', Column: 'column'}

_rename: ClassVar[Mapping[str, str | None]] = {
Expand Down
2 changes: 0 additions & 2 deletions panel/widgets/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class FileDownload(IconMixin):

_transfers = param.Integer(default=0)

_ignored_refs: ClassVar[List[str]] = ['callback']

_mime_types = {
'application': {
'pdf': 'pdf', 'zip': 'zip'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run(self):

install_requires = [
'bokeh >=3.1.1,<3.3.0',
'param >=2.0.0rc2',
'param >=2.0.0rc6',
'pyviz_comms >=0.7.4',
'xyzservices >=2021.09.1', # Bokeh dependency, but pyodide 23.0.0 does not always pick it up
'markdown',
Expand Down Expand Up @@ -226,7 +226,7 @@ def run(self):
# non-python dependencies). Note that setup_requires isn't used
# because it doesn't work well with pip.
extras_require['build'] = [
'param >=2.0.0rc2',
'param >=2.0.0rc6',
'setuptools >=42',
'requests',
'packaging',
Expand Down

0 comments on commit bec9f2f

Please sign in to comment.