(name='hvplot', extension='bokeh', logo=False)
| 11 | |
| 12 | |
| 13 | def patch(name='hvplot', extension='bokeh', logo=False): |
| 14 | try: |
| 15 | from fugue import DataFrames, Outputter |
| 16 | from fugue.extensions import namespace_candidate, parse_outputter |
| 17 | except ImportError: |
| 18 | raise ImportError( |
| 19 | 'Could not add fugue support as it could not be imported. ' |
| 20 | 'Please make sure you have installed fugue in your environment.' |
| 21 | ) |
| 22 | |
| 23 | import hvplot.pandas # noqa: F401 |
| 24 | |
| 25 | class _Visualize(Outputter): |
| 26 | def __init__(self, func: str) -> None: |
| 27 | super().__init__() |
| 28 | self._func = func |
| 29 | getattr(hvPlotTabular, func) # ensure the func exists |
| 30 | |
| 31 | def process(self, dfs: DataFrames) -> None: |
| 32 | """ |
| 33 | Process the dataframes and output the result as |
| 34 | a pn.Column. |
| 35 | |
| 36 | Parameters: |
| 37 | ----------- |
| 38 | dfs: fugue.DataFrames |
| 39 | """ |
| 40 | charts = [] |
| 41 | for df in dfs.values(): |
| 42 | params = dict(self.params) |
| 43 | opts: dict[str, Any] = params.pop('opts', {}) |
| 44 | chart = getattr(df.as_pandas().hvplot, self._func)(**params).opts(**opts) |
| 45 | charts.append(chart) |
| 46 | col = _pn.Column(*charts) |
| 47 | try: |
| 48 | if not _fugue_ipython: |
| 49 | get_ipython() |
| 50 | except NameError: |
| 51 | col.show() # in script |
| 52 | else: |
| 53 | from IPython.display import display |
| 54 | |
| 55 | display(col) # in notebook |
| 56 | |
| 57 | if 'hvplot.fugue' not in _module_extensions: |
| 58 | |
| 59 | @parse_outputter.candidate(namespace_candidate(name, lambda x: isinstance(x, str))) |
| 60 | def _parse_hvplot(obj: tuple[str, str]) -> Outputter: |
| 61 | return _Visualize(obj[1]) |
| 62 | |
| 63 | _module_extensions.add('hvplot.fugue') |
| 64 | |
| 65 | post_patch(extension, logo) |
| 66 | |
| 67 | |
| 68 | patch() |
no test coverage detected
searching dependent graphs…