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

ci: Add numpydoc pre-commit hook #1371

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 3 additions & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ jobs:

- name: Lint
working-directory: skore/
run: pre-commit run --all-files ruff
run: |
pre-commit run --all-files ruff
pre-commit run --all-files numpydoc-validation

backend-lockfiles:
runs-on: "ubuntu-latest"
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ repos:
- id: ruff-format
files: ^(skore/(src|tests))|(examples)/

- repo: https://github.com/numpy/numpydoc
rev: v1.8.0
hooks:
- id: numpydoc-validation
files: ^(skore/src)/

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion examples/skore_project/plot_working_with_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
my_project.put(
"my_string_2",
(
"""Hello world!, **bold**, *italic*, `code`
"""
Hello world!, **bold**, *italic*, `code`

```python
def my_func(x):
Expand Down
8 changes: 8 additions & 0 deletions skore/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ convention = "numpy"
"src/*" = ["UP007"]
"tests/*" = ["D"]

[tool.numpydoc_validation]
checks = [
"all", # Report on all checks, except the below
"ES01", # No "extended summary" section
"EX01", # No "Examples" section
"SA01", # No "See also" section
Comment on lines +123 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those one are quite important for a nice documentation actually.

]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


[tool.typos.default]
extend-ignore-re = [
# Line ignore with trailing `# spellchecker:disable-line`
Expand Down
15 changes: 10 additions & 5 deletions skore/src/skore/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


def _get_threadlocal_config() -> dict[str, Any]:
"""Get a threadlocal **mutable** configuration.
"""
Get a threadlocal **mutable** configuration.

If the configuration does not exist, copy the default global configuration.
"""
Expand All @@ -23,7 +24,8 @@ def _get_threadlocal_config() -> dict[str, Any]:


def get_config() -> dict[str, Any]:
"""Retrieve current values for configuration set by :func:`set_config`.
"""
Retrieve current values for configuration set by :func:`set_config`.

Returns
-------
Expand All @@ -50,7 +52,8 @@ def get_config() -> dict[str, Any]:
def set_config(
show_progress: Union[bool, None] = None,
) -> None:
"""Set skore configuration.
"""
Set skore configuration.

Setting the configuration affects global settings meaning that it will be used
by all skore functions and classes, even in the processes and threads spawned by
Expand Down Expand Up @@ -82,7 +85,8 @@ def config_context(
*,
show_progress: Union[bool, None] = None,
) -> Generator[None, None, None]:
"""Context manager for skore configuration.
"""
Context manager for skore configuration.

Setting the configuration affects global settings meaning that it will be used
by all skore functions and classes, even in the processes and threads spawned by
Expand Down Expand Up @@ -131,7 +135,8 @@ def config_context(


def _set_show_progress_for_testing(show_progress: bool, sleep_duration: float) -> bool:
"""Set the value of show_progress for testing purposes after some waiting.
"""
Set the value of show_progress for testing purposes after some waiting.

This function should exist in a Python module rather than in tests, otherwise
joblib will not be able to pickle it.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


class InvalidProjectNameError(Exception):
"""The project name does not fit with one or more of the project name rules.
"""
The project name does not fit with one or more of the project name rules.

- The project name must start with an alphanumeric character, and must not contain
special characters other than '_' (underscore) and '-' (hyphen).
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/externals/_pandas_accessors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pandas-like accessors.
"""
Pandas-like accessors.

This code is copied from:
https://github.com/pandas-dev/pandas/blob/main/pandas/core/accessor.py
Expand Down
39 changes: 26 additions & 13 deletions skore/src/skore/externals/_sklearn_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ruff: noqa
# mypy: ignore-errors
"""Ease developer experience to support multiple versions of scikit-learn.
"""
Ease developer experience to support multiple versions of scikit-learn.

This file is intended to be vendored in your project if you do not want to depend on
`sklearn-compat` as a package. Then, you can import directly from this file.
Expand Down Expand Up @@ -40,7 +41,8 @@ def _dataclass_args():


def get_tags(estimator):
"""Get estimator tags in a consistent format across different sklearn versions.
"""
Get estimator tags in a consistent format across different sklearn versions.

This function provides compatibility between sklearn versions before and after 1.6.
It returns either a Tags object (sklearn >= 1.6) or a converted Tags object from
Expand Down Expand Up @@ -172,7 +174,8 @@ def validate_params(parameter_constraints, *, prefer_skip_nested_validation):
if sklearn_version < parse_version("1.4"):

def _is_fitted(estimator, attributes=None, all_or_any=all):
"""Determine if an estimator is fitted
"""
Determine if an estimator is fitted

Parameters
----------
Expand Down Expand Up @@ -384,7 +387,8 @@ def type_of_target(y, input_name="", *, raise_unknown=False):
from sklearn.utils.multiclass import type_of_target

def _raise_or_return(target_type):
"""Depending on the value of raise_unknown, either raise an error or
"""
Depending on the value of raise_unknown, either raise an error or
return 'unknown'.
"""
if raise_unknown and target_type == "unknown":
Expand All @@ -410,7 +414,8 @@ def validate_data(
skip_check_array=False,
**kwargs,
):
"""Validate input data and set or check feature names and counts of the input.
"""
Validate input data and set or check feature names and counts of the input.

See the original scikit-learn documentation:
https://scikit-learn.org/stable/modules/generated/sklearn.utils.validation.validate_data.html#sklearn.utils.validation.validate_data
Expand Down Expand Up @@ -468,7 +473,8 @@ def check_array(
estimator=None,
input_name="",
):
"""Input validation on an array, list, sparse matrix or similar.
"""
Input validation on an array, list, sparse matrix or similar.

Check the original documentation for more details:
https://scikit-learn.org/stable/modules/generated/sklearn.utils.check_array.html
Expand Down Expand Up @@ -523,7 +529,8 @@ def check_X_y(
y_numeric=False,
estimator=None,
):
"""Input validation for standard estimators.
"""
Input validation for standard estimators.

Check the original documentation for more details:
https://scikit-learn.org/stable/modules/generated/sklearn.utils.check_X_y.html
Expand Down Expand Up @@ -562,7 +569,8 @@ def check_X_y(
# tags infrastructure
@dataclass(**_dataclass_args())
class InputTags:
"""Tags for the input data.
"""
Tags for the input data.

Parameters
----------
Expand Down Expand Up @@ -622,7 +630,8 @@ class InputTags:

@dataclass(**_dataclass_args())
class TargetTags:
"""Tags for the target data.
"""
Tags for the target data.

Parameters
----------
Expand Down Expand Up @@ -660,7 +669,8 @@ class TargetTags:

@dataclass(**_dataclass_args())
class TransformerTags:
"""Tags for the transformer.
"""
Tags for the transformer.

Parameters
----------
Expand All @@ -679,7 +689,8 @@ class TransformerTags:

@dataclass(**_dataclass_args())
class ClassifierTags:
"""Tags for the classifier.
"""
Tags for the classifier.

Parameters
----------
Expand All @@ -706,7 +717,8 @@ class ClassifierTags:

@dataclass(**_dataclass_args())
class RegressorTags:
"""Tags for the regressor.
"""
Tags for the regressor.

Parameters
----------
Expand All @@ -727,7 +739,8 @@ class RegressorTags:

@dataclass(**_dataclass_args())
class Tags:
"""Tags for the estimator.
"""
Tags for the estimator.

See :ref:`estimator_tags` for more information.

Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/altair_chart_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""AltairChartItem.
"""
AltairChartItem.

This module defines the AltairChartItem class, used to persist Altair Charts.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


class ItemTypeError(Exception):
"""Item type exception.
"""
Item type exception.

Exception raised when an attempt is made to convert an object to an Item, but the
object's type is not supported.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/matplotlib_figure_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""MatplotlibFigureItem.
"""
MatplotlibFigureItem.

This module defines the MatplotlibFigureItem class, used to persist Matplotlib figures.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/media_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""MediaItem.
"""
MediaItem.

This module defines the MediaItem class, used to persist media.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/numpy_array_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NumpyArrayItem.
"""
NumpyArrayItem.

This module defines the NumpyArrayItem class, which represents a NumPy array item.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/pandas_dataframe_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PandasDataFrameItem.
"""
PandasDataFrameItem.

This module defines the PandasDataFrameItem class,
which represents a pandas DataFrame item.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/pandas_series_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PandasSeriesItem.
"""
PandasSeriesItem.

This module defines the PandasSeriesItem class,
which represents a pandas Series item.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/pickle_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PickleItem.
"""
PickleItem.

This module defines the PickleItem class, which is used to persist objects that cannot
be otherwise.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/pillow_image_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PillowImageItem.
"""
PillowImageItem.

This module defines the PillowImageItem class, used to persist Pillow images.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/plotly_figure_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PlotlyFigureItem.
"""
PlotlyFigureItem.

This module defines the PlotlyFigureItem class, used to persist Plotly figures.
"""
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/polars_dataframe_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PolarsDataFrameItem.
"""
PolarsDataFrameItem.

This module defines the PolarsDataFrameItem class,
which represents a polars DataFrame item.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/polars_series_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PolarsSeriesItem.
"""
PolarsSeriesItem.

This module defines the PolarsSeriesItem class,
which represents a polars Series item.
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/item/primitive_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Define PrimitiveItem.
"""
Define PrimitiveItem.

PrimitiveItems represents a primitive item with creation and update timestamps.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SklearnBaseEstimatorItem.
"""
SklearnBaseEstimatorItem.

This module defines the SklearnBaseEstimatorItem class,
which represents a scikit-learn BaseEstimator item.
Expand Down
12 changes: 8 additions & 4 deletions skore/src/skore/persistence/repository/item_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ItemRepository for managing storage and retrieval of items.
"""
ItemRepository for managing storage and retrieval of items.

This module provides the ItemRepository class, which is responsible for
storing, retrieving, and deleting items in a storage system.
Expand Down Expand Up @@ -146,7 +147,8 @@ def __iter__(self) -> Iterator[str]:
yield from self.storage

def set_item_note(self, key: str, note: str, *, version=-1):
"""Attach a note to key ``key``.
"""
Attach a note to key ``key``.

Parameters
----------
Expand Down Expand Up @@ -178,7 +180,8 @@ def set_item_note(self, key: str, note: str, *, version=-1):
raise KeyError((key, version)) from e

def get_item_note(self, key: str, *, version=-1) -> Union[str, None]:
"""Retrieve a note previously attached to key ``key``.
"""
Retrieve a note previously attached to key ``key``.

Parameters
----------
Expand All @@ -203,7 +206,8 @@ def get_item_note(self, key: str, *, version=-1) -> Union[str, None]:
raise KeyError((key, version)) from e

def delete_item_note(self, key: str, *, version=-1):
"""Delete a note previously attached to key ``key``.
"""
Delete a note previously attached to key ``key``.

Parameters
----------
Expand Down
3 changes: 2 additions & 1 deletion skore/src/skore/persistence/view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

@dataclass
class View:
"""A view of a Project.
"""
A view of a Project.

Examples
--------
Expand Down
Loading
Loading