Skip to content

Commit

Permalink
Minor documentation changes (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt authored Jun 19, 2024
1 parent 35a4729 commit b116e67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class B(A):
4
```

As you can see, the Parameters defined here work precisely like any other Python attributes in your code, so it's generally quite straightforward to migrate an existing class to use Param. Just inherit from `param.Parameterized`, then provide an optional `Parameter` declaration for each parameter the object accepts, including ranges and allowed values if appropriate. You only need to declare and document each parameter _once_, at the highest superclass where it applies, and its default value all the other metadata will be inherited by each subclass.
As you can see, the Parameters defined here work precisely like any other Python attributes in your code, so it's generally quite straightforward to migrate an existing class to use Param. Just inherit from `param.Parameterized`, then provide an optional `Parameter` declaration for each parameter the object accepts, including ranges and allowed values if appropriate. You only need to declare and document each parameter _once_, at the highest superclass where it applies, and its default value and all the other metadata will be inherited by each subclass.

Once you've declared your parameters, a whole wealth of features and better behavior is now unlocked! For instance, what happens if a user tries to supply some inappropriate data? With Param, such errors will be caught immediately:

Expand Down
9 changes: 6 additions & 3 deletions doc/user_guide/Parameter_Types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,13 @@
"source": [
"## ClassSelectors\n",
"\n",
"- `param.ClassSelector`: An instance or class of a specified Python class or superclass\n",
"- `param.ClassSelector`: An instance or subclass of a class or tuple of classes\n",
"- `param.Dict`: A Python dictionary\n",
"- `param.Array`: NumPy array\n",
"- `param.Series`: A Pandas Series\n",
"- `param.DataFrame`: A Pandas DataFrame\n",
"\n",
"A ClassSelector has a value that is either an instance or a subclass of a specified Python `class_`. By default, requires an instance of that class, but specifying `is_instance=False` means that a subclass must be selected instead. \n",
"A ClassSelector has a value that is either an instance or a subclass of a specified Python `class_`. By default, requires an instance of that class, but specifying `is_instance=False` means that a subclass must be selected instead.\n",
"\n",
"Like Selector types, all ClassSelector types implement `get_range()`, in this case providing an introspected list of all the concrete (not abstract) subclasses available for the given class. If you want a class to be treated as abstract so that it does not show up in such a list, you can have it declare `__abstract=True` as a class attribute. In a GUI, the range list allows a user to select a type of object they want to create, and they can then separately edit the new object's parameters (if any) to configure it appropriately."
]
Expand All @@ -981,7 +981,10 @@
"source": [
"class C(param.Parameterized):\n",
" e_instance = param.ClassSelector(default=ZeroDivisionError(\"1/0\"), class_=ArithmeticError)\n",
" e_class = param.ClassSelector(default=ZeroDivisionError, class_=ArithmeticError, is_instance=False)\n",
" e_class = param.ClassSelector(\n",
" default=ZeroDivisionError, class_=(ArithmeticError, LookupError),\n",
" is_instance=False\n",
" )\n",
" \n",
"c = C(e_class=OverflowError)\n",
"c.e_class, c.e_instance"
Expand Down
2 changes: 1 addition & 1 deletion param/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@ def get_range(self):

class ClassSelector(SelectorBase):
"""
Parameter allowing selection of either a subclass or an instance of a given set of classes.
Parameter allowing selection of either a subclass or an instance of a class or tuple of classes.
By default, requires an instance, but if is_instance=False, accepts a class instead.
Both class and instance values respect the instantiate slot, though it matters only
for is_instance=True.
Expand Down

0 comments on commit b116e67

Please sign in to comment.