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 docstrings and expand tests for IO sub-module #65

Merged
merged 6 commits into from
Apr 10, 2024

Conversation

K-Meech
Copy link
Contributor

@K-Meech K-Meech commented Apr 8, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
There are very few docstrings for functions in the IO sub-module. Also some parts aren't covered by tests.

What does this PR do?
This PR adds docstrings for all functions in the IO sub-module. It also expands/refactors the tests in test_cell_io

References

For #19

How has this PR been tested?

All tests pass locally.

Is this a breaking change?

No

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@K-Meech K-Meech requested a review from a team April 8, 2024 12:27
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.48%. Comparing base (cacefd6) to head (333e05a).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   86.49%   90.48%   +3.99%     
==========================================
  Files          35       35              
  Lines        1355     1356       +1     
==========================================
+ Hits         1172     1227      +55     
+ Misses        183      129      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@willGraham01 willGraham01 left a comment

Choose a reason for hiding this comment

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

Great stuff - one pathlib.Path convention throughout that I've flagged where I saw it.

Only thing that I'd like some clarity on is the values we're passing to the tests. Seems like a lot of repetition in the hard-coded values - not sure if they can be reduced any further though?

@@ -7,7 +7,8 @@

import logging
import os
from typing import List, Optional
import pathlib
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import pathlib
from pathlib import Path

As far as I can tell we only use Path, and the rest of the BG codebase errs towards from pathlib import Path.

Comment on lines 266 to 268
def cells_to_csv(cells: List[Cell], csv_file_path: Union[str, pathlib.Path]):
"""Save cells to csv file"""

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def cells_to_csv(cells: List[Cell], csv_file_path: Union[str, pathlib.Path]):
"""Save cells to csv file"""
def cells_to_csv(cells: List[Cell], csv_file_path: Union[str, Path]):
"""Save cells to csv file"""

To be consistent with the import change above.

Also there's a trailing newlines between the docstring and first command in the function which isn't present in the others.

brainglobe_utils/IO/cells.py Outdated Show resolved Hide resolved
brainglobe_utils/IO/cells.py Outdated Show resolved Hide resolved

Parameters
----------
xml_file_path : str or pathlib.Path
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
xml_file_path : str or pathlib.Path
xml_file_path : str or Path

brainglobe_utils/IO/cells.py Outdated Show resolved Hide resolved
----------
marching_cubes_out : tuple of np.ndarray
Output from skimage.measure.marching_cubes.
output_file : str or pathlib.Path
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed another pathlib.Path here, but in another file. Could you double-check if we're using anything else from pathlib in this file?


Parameters
----------
yaml_file : str or pathlib.Path
Copy link
Contributor

Choose a reason for hiding this comment

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

(Will's pathlib.Path rant continues)

tests/tests/test_IO/test_cell_io.py Show resolved Hide resolved
tests/tests/test_IO/test_cell_io.py Show resolved Hide resolved
@K-Meech
Copy link
Contributor Author

K-Meech commented Apr 10, 2024

@willGraham01 I've looked through brainglobe_utils and turns out there are many files that use pathlib.Path rather than Path. Are you happy for me to merge this PR as-is, then make a separate PR to fix all the Path issues at once? Otherwise, it will introduce changes across files outside the IO sub-module.

@willGraham01
Copy link
Contributor

Are you happy for me to merge this PR as-is, then make a separate PR to fix all the Path issues at once? Otherwise, it will introduce changes across files outside the IO sub-module.

Yep happy for this to go in as it is. I'll open a PR of my own to change all the pathlib.Path syntax across the package since that's become a pet peeve of mine 😅

@willGraham01 willGraham01 merged commit 3b632c2 into main Apr 10, 2024
12 checks passed
@willGraham01 willGraham01 deleted the IO_docstrings_tests branch April 10, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants