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

Add pre-commit #967

Merged
merged 8 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,24 @@ env:
CACHE_VERSION: 3

jobs:
pre_commit:
name: Run pre-commit hooks
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: "1"
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: pre-commit
uses: pre-commit/action@v3.0.0
test_suite:
name: Pytest on ${{ matrix.os }} with Python ${{ matrix.python-version }}
needs: [pre_commit]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -36,7 +52,7 @@ jobs:
timeout-minutes: 90
defaults:
run:
shell: bash -l {0}
shell: bash -l {0}
env:
DESC: "Python ${{ matrix.python-version }} tests"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -110,6 +126,7 @@ jobs:
codecov
test_suite_36:
name: Pytest on ${{ matrix.os }} with Python ${{ matrix.python-version }}
needs: [pre_commit]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -126,7 +143,7 @@ jobs:
timeout-minutes: 90
defaults:
run:
shell: bash -l {0}
shell: bash -l {0}
env:
DESC: "Python ${{ matrix.python-version }} tests"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -169,7 +186,7 @@ jobs:
# can be installed on Python 3.6 but are actually not compatible with Python 3.6
# Panel 0.13 will support Python >= 3.7 only so the pin here can stay indefinitely.
# - Install importlib_resources to fix tqdm that missed adding it as a dependency
# for 3.6 (https://github.com/conda-forge/tqdm-feedstock/pull/114)
# for 3.6 (https://github.com/conda-forge/tqdm-feedstock/pull/114)
conda install "panel=0.12" "importlib_resources" --no-update-deps
- name: hvplot install if env cached
if: steps.cache.outputs.cache-hit == 'true'
Expand Down
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This is the configuration for pre-commit, a local framework for managing pre-commit hooks
# Check out the docs at: https://pre-commit.com/

default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-toml
- id: detect-private-key
- id: end-of-file-fixer
exclude: (\.min\.js$|\.svg$)
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8 # See 'setup.cfg' for args
args: [hvplot]
files: hvplot/
18 changes: 15 additions & 3 deletions doc/developer_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ development versions of the other HoloViz packages, such as HoloViews or Panel.
conda install mamba -c conda-forge
conda create -n hvplot_dev
conda activate hvplot_dev
conda config --env --append channels pyviz/label/dev --append channels conda-forge --append channels nodefaults
conda config --env --append channels pyviz/label/dev --append channels conda-forge
conda config --env --remove channels defaults

Since hvPlot interfaces with a large range of different libraries the
Expand Down Expand Up @@ -106,6 +106,18 @@ suite and all the examples:
Add ``-o doc`` if you want to install the dependencies required to build
the website.

Setting up pre-commit
~~~~~~~~~~~~~~~~~~~~~

hvPlot uses ``pre-commit`` to automatically apply linting to hvPlot code.
If you intend to contribute to hvPlot we recommend you enable it with:

.. code-block:: sh

pre-commit install

This will ensure that every time you make a commit linting will automatically be applied.

.. _devguide_python_setup:

Commands
Expand All @@ -123,8 +135,8 @@ You can list the available `doit` commands with `doit list`.
env_create Create named environment if it doesn't already exist
env_dependency_graph Write out dependency graph of named environment.
env_export Generate a pinned environment.yaml from specified env, filtering
env_export2
list_envs
env_export2
list_envs
miniconda_download Download Miniconda3-latest
miniconda_install Install Miniconda3-latest to location if not already present
package_build Build and then test conda.recipe/ (or specified alternative).
Expand Down
1 change: 0 additions & 1 deletion doc/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ For versions of `jupyterlab>=3.0` the necessary extension is automatically bundl
To run the guides in this site create an environment with the required dependencies:

conda create -n hvplot-env -c pyviz -c conda-forge -c nodefaults hvplot geoviews datashader xarray pandas geopandas dask streamz networkx intake intake-xarray intake-parquet s3fs scipy spatialpandas pooch rasterio fiona plotly matplotlib jupyterlab

3 changes: 1 addition & 2 deletions doc/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ This is a major release that includes bug fixes, changes to default behavior, an

Features:
- Widget handling capabilities to facilitate interactivity ([#323](https://github.com/holoviz/hvplot/pull/323), [#331](https://github.com/holoviz/hvplot/pull/331))
- New default colormaps ([#258](https://github.com/holoviz/hvplot/pull/258), [#316](https://github.com/holoviz/hvplot/pull/316), [#206](https://github.com/holoviz/hvplot/pull/206))
- New default colormaps ([#258](https://github.com/holoviz/hvplot/pull/258), [#316](https://github.com/holoviz/hvplot/pull/316), [#206](https://github.com/holoviz/hvplot/pull/206))
- long_name(units) used to label xarray objects ([#173](https://github.com/holoviz/hvplot/pull/173))
- Derived datetime accessor handlind ([#263](https://github.com/holoviz/hvplot/pull/263), [#286](https://github.com/holoviz/hvplot/pull/286))
- `coastline` and `tiles` options for easy geo plots.
Expand Down Expand Up @@ -283,4 +283,3 @@ This release includes a number of major improvements to the documentation and co
- Exposed bokeh styling options for all plot types ([#134](https://github.com/pyviz/hvplot/pull/134))
- Compatibility with latest HoloViews/GeoViews releases ([#113](https://github.com/pyviz/hvplot/pull/113), [#118](https://github.com/pyviz/hvplot/pull/118), [#134](https://github.com/pyviz/hvplot/pull/134))
- Added control over tools ([#120](https://github.com/pyviz/hvplot/pull/120)) and legend position ([#119](https://github.com/pyviz/hvplot/pull/119))

1 change: 0 additions & 1 deletion doc/user_guide/Streaming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ _________

.. notebook:: hvplot ../../examples/user_guide/Streaming.ipynb
:skip_execute: True

10 changes: 5 additions & 5 deletions hvplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def bind(function, *args, **kwargs):
"""
Returns a *reactive* function that can be used to start your `.interactive` pipeline by running
a model or loading data depending on inputs from widgets, parameters or python objects.

The widgets can be Panel or ipywidgets.

Reference: https://hvplot.holoviz.org/user_guide/Interactive.html#functions-as-inputs

Parameters
Expand All @@ -239,16 +239,16 @@ def bind(function, *args, **kwargs):

>>> import pandas as pd
>>> import numpy as np

>>> def algorithm(alpha):
... # An example algorithm that uses alpha ...
... return pd.DataFrame({"output": (np.array(range(0,100)) ** alpha)*50})

Make it **interactive** using `.bind`, `.interactive` and widgets.

>>> import hvplot
>>> import panel as pn

>>> alpha = pn.widgets.FloatSlider(value=0.5, start=0, end=1.0, step=0.1, name="Alpha")
>>> top = pn.widgets.RadioButtonGroup(value=10, options=[5, 10, 25], name="Top")
>>> interactive_table = (
Expand Down
32 changes: 16 additions & 16 deletions hvplot/backend_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _transfer_opts_cur_backend(element):
'text_alpha': lambda k, v: ('alpha', v),
'text_baseline': lambda k, v: ('verticalalignment', _text_baseline_bk_mpl_mapping.get(v, UNSET)),
'text_color': lambda k, v: ('color', v),
'text_font': UNSET,
'text_font': UNSET,
'text_font_size': lambda k, v: ('size', v),
'text_font_style': UNSET,
'box_alpha': UNSET,
Expand Down Expand Up @@ -265,21 +265,21 @@ def _transfer_opts_cur_backend(element):
'edge_line_dash': lambda k, v: ('edge_linestyle', v),
'edge_line_join': UNSET,
'edge_line_width': lambda k, v: ('edge_linewidth', v),
'edge_visible': UNSET,
'node_alpha': lambda k, v: ('node_alpha', v),
'node_cmap': lambda k, v: ('node_cmap', v),
'node_color': lambda k, v: ('node_color', v),
'node_fill_alpha': UNSET,
'node_fill_color': lambda k, v: ('node_facecolors', v),
'node_line_alpha': UNSET,
'node_line_cap': UNSET,
'node_line_color': lambda k, v: ('node_edgecolors', v),
'node_line_dash': UNSET,
'node_line_join': UNSET,
'node_line_width': lambda k, v: ('node_linewidth', v),
'node_marker': lambda k, v: ('node_marker', v),
'node_radius': UNSET,
'node_size': lambda k, v: ('node_size', v),
'edge_visible': UNSET,
'node_alpha': lambda k, v: ('node_alpha', v),
'node_cmap': lambda k, v: ('node_cmap', v),
'node_color': lambda k, v: ('node_color', v),
'node_fill_alpha': UNSET,
'node_fill_color': lambda k, v: ('node_facecolors', v),
'node_line_alpha': UNSET,
'node_line_cap': UNSET,
'node_line_color': lambda k, v: ('node_edgecolors', v),
'node_line_dash': UNSET,
'node_line_join': UNSET,
'node_line_width': lambda k, v: ('node_linewidth', v),
'node_marker': lambda k, v: ('node_marker', v),
'node_radius': UNSET,
'node_size': lambda k, v: ('node_size', v),
'node_visible': lambda k, v: ('visible', v),
},
}
Expand Down
18 changes: 9 additions & 9 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class HoloViewsConverter:
If `cnorm='eq_hist` and there are only a few discrete values,
then `rescale_discrete_levels=True` (the default) decreases
the lower limit of the autoranged span so that the values are
rendering towards the (more visible) top of the `cmap` range,
rendering towards the (more visible) top of the `cmap` range,
thus avoiding washout of the lower values. Has no effect if
`cnorm!=`eq_hist`.
responsive: boolean
Expand Down Expand Up @@ -194,15 +194,15 @@ class HoloViewsConverter:
very large if dynamic=False)
datashade (default=False):
Whether to apply rasterization and shading (colormapping) using
the Datashader library, returning an RGB object instead of
the Datashader library, returning an RGB object instead of
individual points
dynspread (default=False):
For plots generated with datashade=True or rasterize=True,
For plots generated with datashade=True or rasterize=True,
automatically increase the point size when the data is sparse
so that individual points become more visible
rasterize (default=False):
Whether to apply rasterization using the Datashader library,
returning an aggregated Image (to be colormapped by the
returning an aggregated Image (to be colormapped by the
plotting backend) instead of individual points
x_sampling/y_sampling (default=None):
Specifies the smallest allowed sampling interval along the x/y axis.
Expand Down Expand Up @@ -630,7 +630,7 @@ def _process_symmetric(self, symmetric, clim, check_symmetric_max):

if data.size == 0:
return False

cmin = np.nanquantile(data, 0.05)
cmax = np.nanquantile(data, 0.95)

Expand Down Expand Up @@ -786,13 +786,13 @@ def _process_data(self, kind, data, x, y, by, groupby, row, col,
groupby = [g for g in groupby if g not in grid]

# Add a title to hvplot.xarray plots that displays scalar coords values,
# as done by xarray.plot()
# as done by xarray.plot()
if not groupby and not grid:
if isinstance(da, xr.DataArray):
self._title = da._title_for_slice()
elif isinstance(da, xr.Dataset):
self._title = partial(xr.DataArray._title_for_slice, da)()

self.data = data
else:
raise ValueError('Supplied data type %s not understood' % type(data).__name__)
Expand Down Expand Up @@ -1325,7 +1325,7 @@ def method_wrapper(ds, x, y):
if self.dynspread:
processed = dynspread(processed, max_px=self.kwds.get('max_px', 3),
threshold=self.kwds.get('threshold', 0.5))

opts = filter_opts(eltype, dict(self._plot_opts, **style), backend='bokeh')
layers = self._apply_layers(processed).opts(eltype, **opts, backend='bokeh')
layers = _transfer_opts_cur_backend(layers)
Expand Down Expand Up @@ -1486,7 +1486,7 @@ def single_chart(self, element, x, y, data=None):
labelled.append('x')
if 'ylabel' in self._plot_opts and 'y' not in labelled:
labelled.append('y')

cur_el_opts = self._get_opts(element.name, labelled=labelled, backend='bokeh')
compat_el_opts = self._get_opts(element.name, labelled=labelled, backend=self._backend_compat)
for opts_ in [cur_el_opts, compat_el_opts]:
Expand Down
2 changes: 1 addition & 1 deletion hvplot/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def patch(name='hvplot', extension='bokeh', logo=False):
_patch_plot.__doc__ = hvPlotTabular.__call__.__doc__
patch_property = property(_patch_plot)
setattr(ibis.Expr, name, patch_property)

post_patch(extension, logo)

patch()
Loading