Skip to content

Commit

Permalink
docs: add optional dependency detail for hvplot and seaborn
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjholland committed Jan 3, 2025
1 parent f3740bf commit 0045fd4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/source/user_guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ The steps to install PyProBE are as follows:
pip install PyProBE-Data
Optional dependencies can be added to the installation as follows:

.. code-block:: bash
pip install 'PyProBE-Data[hvplot]'
If a method uses an optional dependency, it will be detailed in the
:doc:`api documentation <pyprobe>`. If these methods is run without their dependencies
installed, they will return an error.

3. You can create a new python script or jupyter notebook to
process your data. You can import PyProBE into your script as follows:

Expand Down
9 changes: 8 additions & 1 deletion pyprobe/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __getattr__(self, _: Any) -> None:
"""Raise an ImportError if seaborn is not installed."""
raise ImportError(
"Optional dependency 'seaborn' is not installed. Please install by "
"running 'pip install seaborn'."
"running 'pip install seaborn' or installing PyProBE with seaborn "
"as an optional dependency: `pip install 'PyProBE-Data[seaborn]'."
)

return SeabornWrapper()
Expand Down Expand Up @@ -124,11 +125,17 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
seaborn = _create_seaborn_wrapper()
"""A wrapped version of the seaborn package.
Requires the seaborn package to be installed as an optional dependency. You can install
it with PyProBE by running :code:`pip install 'PyProBE-Data[seaborn]'`, or install it
seperately with :code:`pip install seaborn`.
This version of seaborn is modified to work with PyProBE Result objects. All functions
from the original seaborn package are available in this version. Where seaborn functions
accept a 'data' argument, a PyProBE Result object can be passed instead of a pandas
DataFrame. For example:
.. code-block:: python
from pyprobe.plot import seaborn as sns
result = cell.procedure['Sample']
Expand Down
20 changes: 13 additions & 7 deletions pyprobe/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,27 @@ def hvplot(self, *args: Any, **kwargs: Any) -> None:
data_to_plot = _retrieve_relevant_columns(self, args, kwargs)
return data_to_plot.hvplot(*args, **kwargs)

hvplot.__doc__ = (
"HvPlot is a library for creating fast and interactive plots.\n\n"
"The default backend is bokeh, which can be changed by setting the backend "
"with :code:`hvplot.extension('matplotlib')` or "
":code:`hvplot.extension('plotly')`.\n\n" + (hvplot.__doc__ or "")
)
else:

def hvplot(self, *args: Any, **kwargs: Any) -> None:
"""Wrapper for plotting using the hvplot library."""
raise ImportError(
"Optional dependency hvplot is not installed. Please install it via "
"'pip install hvplot'."
"'pip install hvplot' or by installing PyProBE with hvplot as an "
"optional dependency: pip install 'PyProBE-Data[hvplot]'."
)

hvplot.__doc__ = (
"HvPlot is a library for creating fast and interactive plots.\n\n"
"This method requires the hvplot library to be installed as an optional "
"dependency. You can install it with PyProBE by running "
":code:`pip install 'PyProBE-Data[hvplot]'`, or install it seperately with "
":code:`pip install hvplot`.\n\n"
"The default backend is bokeh, which can be changed by setting the backend "
"with :code:`hvplot.extension('matplotlib')` or "
":code:`hvplot.extension('plotly')`.\n\n" + (hvplot.__doc__ or "")
)

def _get_data_subset(self, *column_names: str) -> pl.DataFrame:
"""Return a subset of the data with the specified columns.
Expand Down

0 comments on commit 0045fd4

Please sign in to comment.