Skip to content

Commit

Permalink
maintain: add more pre-commit hooks (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislemke authored and premsrii committed Jan 13, 2023
1 parent 170c39a commit 6bcb05c
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 56 deletions.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,47 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-xml
- id: mixed-line-ending
args: ["--fix=lf"]
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- id: fix-byte-order-marker
- id: forbid-new-submodules
- id: forbid-submodules
- id: detect-private-key
- id: no-commit-to-branch
args: ["--branch=main", "--branch=develop"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-use-type-annotations
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: text-unicode-replacement-char

- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
hooks:
- id: docformatter

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.1
hooks:
- id: nbqa-check-ast
- id: nbqa-mypy
args: ["--config-file=pyproject.toml"]
- id: nbqa-pyupgrade

- repo: https://github.com/bwhmather/ssort
rev: v0.11.6
Expand All @@ -57,6 +87,10 @@ repos:
rev: 22.12.0
hooks:
- id: black
args: ["--config=pyproject.toml"]
- id: black-jupyter
args: ["--config=pyproject.toml"]
files: \.ipynb$

- repo: https://github.com/PyCQA/isort
rev: 5.11.4
Expand Down Expand Up @@ -86,6 +120,11 @@ repos:
args:
- "-r"

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout

- repo: https://github.com/python-poetry/poetry
rev: 1.3.0
hooks:
Expand Down
105 changes: 94 additions & 11 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/blitzly/etc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def save_show_return(
fig: BaseFigure, write_html_path: Optional[str] = None, show: bool = True
) -> BaseFigure:

"""
Saves the figure if needed, shows the figure if needed, and returns a it.
"""Saves the figure if needed, shows the figure if needed, and returns a
it.
Args:
fig (BaseFigure): The Plotly figure.
Expand All @@ -38,8 +38,8 @@ def update_figure_layout(
show_scale: Optional[bool] = None,
) -> BaseFigure:

"""
Updates the figure by setting the title and also scales the plot to the given size.
"""Updates the figure by setting the title and also scales the plot to the
given size.
Args:
fig (BaseFigure): The Plotly figure.
Expand Down Expand Up @@ -81,8 +81,7 @@ def check_data(
max_columns: Optional[int] = None,
as_pandas: bool = False,
) -> Union[NDArray[Any], pd.DataFrame, pd.Series]:
"""
Checks if the data is valid for plotting. The function checks for:
"""Checks if the data is valid for plotting. The function checks for:
- The data is a DataFrame or numpy array of values.
Expand Down
11 changes: 5 additions & 6 deletions src/blitzly/plots/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def _check_data_ready_for_bar(
hover_texts: Optional[List[str]] = None,
errors: Optional[Union[pd.DataFrame, pd.Series, NDArray]] = None,
) -> None:
"""
Checks whether the data is ready for plotting.
"""Checks whether the data is ready for plotting.
Args:
data (Union[pd.DataFrame, pd.Series, NDArray]): The data to plot.
Expand Down Expand Up @@ -79,10 +78,10 @@ def multi_bar(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Creates a bar chart with multiple groups. Each group is represented by a bar. The bars are grouped by the x-axis.
The number of `group_labels` must be equal to the number of rows in the data.
The number of `x_labels` must be equal to the number of columns in the data.
"""Creates a bar chart with multiple groups. Each group is represented by a
bar. The bars are grouped by the x-axis. The number of `group_labels` must
be equal to the number of rows in the data. The number of `x_labels` must
be equal to the number of columns in the data.
Example:
```python
Expand Down
7 changes: 3 additions & 4 deletions src/blitzly/plots/dumbbell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ def simple_dumbbell(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Creates a dumbbell plot. These are useful to show the difference between
"""Creates a dumbbell plot. These are useful to show the difference between
two sets of data which have the same categories. For instance, it can be
used to compare two binary classifiers by plotting the various classification
metrics.
used to compare two binary classifiers by plotting the various
classification metrics.
Example:
```python
Expand Down
4 changes: 2 additions & 2 deletions src/blitzly/plots/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def simple_histogram(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Create a simple histogram from a pandas DataFrame, numpy array, or list of values.
"""Create a simple histogram from a pandas DataFrame, numpy array, or list
of values.
Example:
```python
Expand Down
3 changes: 1 addition & 2 deletions src/blitzly/plots/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def binary_confusion_matrix(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Creates a confusion matrix for binary classification.
"""Creates a confusion matrix for binary classification.
Example:
```python
Expand Down
25 changes: 12 additions & 13 deletions src/blitzly/plots/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def dimensionality_reduction(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Create a scatter plot of the dimensionality reduction representation of the data provided.
Multiple dimensionality reduction functions can be used. The data is scaled using the `scaler_func`.
If multiple functions are used, the plots are arranged in a grid using
"""Create a scatter plot of the dimensionality reduction representation of
the data provided. Multiple dimensionality reduction functions can be used.
The data is scaled using the `scaler_func`. If multiple functions are used,
the plots are arranged in a grid using.
[`make_subplots`](https://invia-flights.github.io/blitzly/plots/subplots/#blitzly.subplots.make_subplots) from blitzly ⚡️.
Example:
Expand Down Expand Up @@ -63,7 +64,6 @@ def dimensionality_reduction(
show (bool): Whether to show the figure.
write_html_path (Optional[str]): The path to which the histogram should be written as an HTML file.
If None, the histogram will not be saved.
"""

func_list = [
Expand Down Expand Up @@ -175,11 +175,11 @@ def scatter_matrix(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Create a scatter matrix plot. It can be used to visualize the relationship between multiple variables.
The scatter matrix is a grid of scatter plots, one for each pair of variables in the data. The diagonal
plots are histograms of the corresponding variables. It is also useful for visualizing the distribution of each
variable.
"""Create a scatter matrix plot. It can be used to visualize the
relationship between multiple variables. The scatter matrix is a grid of
scatter plots, one for each pair of variables in the data. The diagonal
plots are histograms of the corresponding variables. It is also useful for
visualizing the distribution of each variable.
Example:
```python
Expand Down Expand Up @@ -269,9 +269,8 @@ def multi_scatter(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Create a multi scatter plot. It can be used to visualize the relationship between
multiple variables from the same Pandas DataFrame.
"""Create a multi scatter plot. It can be used to visualize the
relationship between multiple variables from the same Pandas DataFrame.
Example:
```python
Expand Down
7 changes: 3 additions & 4 deletions src/blitzly/plots/slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ def simple_slope(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Creates a slope plot. These are useful to show the difference between
"""Creates a slope plot. These are useful to show the difference between
two sets of data which have the same categories. For instance, it can be
used to compare two binary classifiers by plotting the various classification
metrics.
used to compare two binary classifiers by plotting the various
classification metrics.
Example:
```python
Expand Down
11 changes: 5 additions & 6 deletions src/blitzly/subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
def _check_shape_for_subplots(
subfig_list: List[BaseFigure], shape: Tuple[int, int]
) -> None:
"""
Checks whether the `shape` is compatible for making subplots.
"""Checks whether the `shape` is compatible for making subplots.
Args:
subfig_list (List[BaseFigure]): A list of figure objects.
Expand Down Expand Up @@ -42,10 +41,10 @@ def make_subplots(
write_html_path: Optional[str] = None,
) -> BaseFigure:

"""
Creates subplots using a provided list of figure objects.
`plotly.subplots.make_subplots` requires the use of traces. This function is an
alternative implementation that directly uses previously-created figure objects.
"""Creates subplots using a provided list of figure objects.
`plotly.subplots.make_subplots` requires the use of traces. This function
is an alternative implementation that directly uses previously-created
figure objects.
Example:
```python
Expand Down
3 changes: 1 addition & 2 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def fig_to_array(fig: Figure) -> NDArray[Any]:
"""
Convert a plotly figure to a numpy array.
"""Convert a plotly figure to a numpy array.
Args:
fig (plotly.graph_objects.Figure): The plotly figure which should be converted.
Expand Down

0 comments on commit 6bcb05c

Please sign in to comment.