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 numpdoc validation to .pre-commit-config.yaml #243

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1e905aa
Add numpdoc validation to .pre-commit-config.yaml
pauladkisson Sep 14, 2023
7676455
added numpydoc validation to pre-commit (linked to most recent commit)
pauladkisson Sep 14, 2023
54b62d4
Merge branch 'main' into numpydoc
pauladkisson Oct 2, 2023
ca03afe
excluded missing docstring from numpydoc validation pre-commit
pauladkisson Oct 2, 2023
7975201
excluded missing docstring from numpydoc validation pre-commit
pauladkisson Oct 2, 2023
04881a0
excluded testing methods starting with 'test_', 'check_', and 'assert_'
pauladkisson Oct 2, 2023
9d7d828
added comments on excluded sections
pauladkisson Oct 2, 2023
7096d41
aider: Added hello_world.txt
pauladkisson Oct 2, 2023
505a4d4
added .aider to gitignore
pauladkisson Oct 2, 2023
3cba99d
Added hello_world.py
pauladkisson Oct 2, 2023
e998bcb
aider: Refactor hello_world function to include a docstring.
pauladkisson Oct 2, 2023
70ad437
remove aider tester files
pauladkisson Oct 2, 2023
6073ba5
aider: Fix docstring formatting issues in `generate_dummy_imaging_ext…
pauladkisson Oct 2, 2023
5803b95
aider: Refactored `generate_dummy_segmentation_extractor` to return a…
pauladkisson Oct 2, 2023
2331264
aider: Fix docstring formatting and type hints in `generate_dummy_vid…
pauladkisson Oct 2, 2023
8f4785a
aider: Fixed docstring formatting and parameter name typo in `generat…
pauladkisson Oct 2, 2023
20ebf82
undo aider commits
pauladkisson Oct 2, 2023
361c609
aider: Fix docstring issues in src/roiextractors/testing.py.
pauladkisson Oct 3, 2023
289c78e
aider: Fixed typos in the docstrings of the `generate_dummy_segmentat…
pauladkisson Oct 3, 2023
ab6cdfc
aider: Fix numpydoc validation error in generate_dummy_video docstring.
pauladkisson Oct 3, 2023
e308db6
Generate dummy imaging and segmentation extractors for testing.
pauladkisson Oct 3, 2023
c4aab3e
aider: Fixed docstring of `generate_dummy_segmentation_extractor` to …
pauladkisson Oct 3, 2023
5ef427f
undo aider commits
pauladkisson Oct 3, 2023
3aa2ac2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2023
58dfd93
reset testing file
pauladkisson Oct 4, 2023
48dca22
updated numpydoc validation exceptions
pauladkisson Oct 4, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,6 @@ fabric.properties
# Repo specific items
tests/gin_test_config.json
.pre-commit-config.yaml

# Aider coding assistant
.aider*
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ repos:
args:
- --convention=numpy
- --add-ignore=D1
- repo: https://github.com/numpy/numpydoc
rev: 881c0abf0a75c1b517c23a819f9365fbfc9cded7
hooks:
- id: numpydoc-validation
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@ extend-exclude = '''
| dist
)/
'''

[tool.numpydoc_validation]
checks = [
"all", # report on all checks, except the below
"GL08", # Missing docstring
"EX01", # Missing Example section
"SA01", # Missing See Also section
"ES01", # Missing Extended Summary section
"GL01", # Missing newline at beginning of docstring
"RT02", # Return should only specify type NOT name
]
exclude = [ # don't report on objects that match any of these regex
'test_',
'check_',
'assert_',
]
override_SS05 = [ # override SS05 to allow docstrings starting with these words
]
23 changes: 16 additions & 7 deletions src/roiextractors/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,19 @@ def generate_dummy_segmentation_extractor(


def _assert_iterable_shape(iterable, shape):
"""Assert that the iterable has the given shape. If the iterable is a numpy array, the shape is checked directly."""
"""Assert that the iterable has the given shape.

If the iterable is a numpy array, the shape is checked directly.
"""
ar = iterable if isinstance(iterable, np.ndarray) else np.array(iterable)
for ar_shape, given_shape in zip(ar.shape, shape):
if isinstance(given_shape, int):
assert ar_shape == given_shape, f"Expected {given_shape}, received {ar_shape}!"


def _assert_iterable_shape_max(iterable, shape_max):
"""Assert that the iterable has a shape less than or equal to the given maximum shape."""
"""Assert that the iterable has a shape less than or equal to the given
maximum shape."""
ar = iterable if isinstance(iterable, np.ndarray) else np.array(iterable)
for ar_shape, given_shape in zip(ar.shape, shape_max):
if isinstance(given_shape, int):
Expand All @@ -216,7 +220,8 @@ def _assert_iterable_element_dtypes(iterable, dtypes):


def _assert_iterable_complete(iterable, dtypes=None, element_dtypes=None, shape=None, shape_max=None):
"""Assert that the iterable is complete, i.e. it is not None and has the given dtypes, element_dtypes, shape and shape_max."""
"""Assert that the iterable is complete, i.e. it is not None and has the
given dtypes, element_dtypes, shape and shape_max."""
assert isinstance(iterable, dtypes), f"iterable {type(iterable)} is none of the types {dtypes}"
if not isinstance(iterable, NoneType):
if shape is not None:
Expand Down Expand Up @@ -270,7 +275,8 @@ def check_segmentations_images(
segmentation_extractor1: SegmentationExtractor,
segmentation_extractor2: SegmentationExtractor,
):
"""Check that the segmentation images are equal for the given segmentation extractors."""
"""Check that the segmentation images are equal for the given segmentation
extractors."""
images_in_extractor1 = segmentation_extractor1.get_images_dict()
images_in_extractor2 = segmentation_extractor2.get_images_dict()

Expand All @@ -287,7 +293,8 @@ def check_segmentations_images(


def check_segmentation_return_types(seg: SegmentationExtractor):
"""Check that the return types of the segmentation extractor are correct."""
"""Check that the return types of the segmentation extractor are
correct."""
assert isinstance(seg.get_num_rois(), int)
assert isinstance(seg.get_num_frames(), int)
assert isinstance(seg.get_num_channels(), int)
Expand Down Expand Up @@ -378,9 +385,11 @@ def check_imaging_equal(


def assert_get_frames_return_shape(imaging_extractor: ImagingExtractor):
"""Check whether an ImagingExtractor get_frames function behaves as expected.
"""Check whether an ImagingExtractor get_frames function behaves as
expected.

We aim for the function to behave as numpy slicing and indexing as much as possible.
We aim for the function to behave as numpy slicing and indexing as
much as possible.
"""
image_size = imaging_extractor.get_image_size()

Expand Down
Loading