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

[DOC] move default from end of argument description to type name #4040

Merged
merged 40 commits into from Oct 17, 2023

Conversation

Remi-Gau
Copy link
Collaborator

@Remi-Gau Remi-Gau commented Oct 8, 2023

Changes proposed in this pull request:

  • add script to move default
  • run script
  • lint and fix

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "python /home/remi/github/nilearn/maint_tools/check_defaults.py",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^
@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2023

👋 @Remi-Gau Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.

  • PR has an interpretable title.
  • PR links to Github issue with mention Closes #XXXX (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.

nilearn/_utils/ndimage.py Outdated Show resolved Hide resolved
nilearn/_utils/ndimage.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/datasets/struct.py Outdated Show resolved Hide resolved
nilearn/glm/thresholding.py Outdated Show resolved Hide resolved
nilearn/glm/thresholding.py Outdated Show resolved Hide resolved
nilearn/glm/thresholding.py Outdated Show resolved Hide resolved
nilearn/glm/thresholding.py Outdated Show resolved Hide resolved
nilearn/glm/thresholding.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 8, 2023

Codecov Report

Merging #4040 (3fb3c69) into main (b6f4ff0) will increase coverage by 0.02%.
Report is 5 commits behind head on main.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #4040      +/-   ##
==========================================
+ Coverage   91.48%   91.50%   +0.02%     
==========================================
  Files         143      143              
  Lines       16076    16072       -4     
  Branches     3340     3339       -1     
==========================================
  Hits        14707    14707              
+ Misses        823      820       -3     
+ Partials      546      545       -1     
Flag Coverage Δ
macos-latest_3.10 ?
macos-latest_3.11 ?
macos-latest_3.12 ?
macos-latest_3.8 91.45% <ø> (+0.02%) ⬆️
macos-latest_3.9 91.46% <ø> (+0.02%) ⬆️
ubuntu-latest_3.10 ?
ubuntu-latest_3.11 ?
ubuntu-latest_3.12 ?
ubuntu-latest_3.8 ?
ubuntu-latest_3.9 ?
windows-latest_3.10 91.43% <ø> (+0.02%) ⬆️
windows-latest_3.11 91.43% <ø> (?)
windows-latest_3.12 91.43% <ø> (+0.02%) ⬆️
windows-latest_3.8 ?
windows-latest_3.9 91.40% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
nilearn/_utils/cache_mixin.py 80.64% <ø> (ø)
nilearn/_utils/class_inspect.py 100.00% <ø> (ø)
nilearn/_utils/data_gen.py 95.52% <ø> (ø)
nilearn/_utils/docs.py 91.86% <ø> (ø)
nilearn/_utils/extmath.py 89.47% <ø> (ø)
nilearn/_utils/helpers.py 75.86% <ø> (ø)
nilearn/_utils/logger.py 100.00% <ø> (ø)
nilearn/_utils/ndimage.py 88.88% <ø> (ø)
nilearn/_utils/niimg.py 97.11% <ø> (ø)
nilearn/_utils/niimg_conversions.py 90.47% <ø> (ø)
... and 73 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Remi-Gau
Copy link
Collaborator Author

Remi-Gau commented Oct 9, 2023

@bthirion @ymzayek
Let me know if you want me to split this PR into several smaller ones to make the review less painful.

@@ -262,7 +262,9 @@ def custom_function(vertices):
] = """
data_dir : :obj:`pathlib.Path` or :obj:`str`, optional
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we change optional to default=None here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is one thing I think we should probably discuss a bit because in many cases if the default is None then in many cases the code itself will set it to something else if it is None.

In this case if None is passed then data will be installed in the home folder tof the user.

There are many other cases like this in the codebase.

For the moment in this PR I have tried to mostly just move the default that was already in the description to the end of the "type" section.

But it may be good to sort of decide if this default should just be what is in the function declaration or if it should try to show what the "effective" default will be in the cases when None is passed.

I have a slight preference for the latter because it makes the doc a bit more informative and does not just repeat the function définition.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, we can leave for now.
Though this also applies when an option is e.g. "auto" and it could be the case that the "effective" default of a parameter being left as None changes according to other parameters. But this is or should be addressed rather in the parameter description.

Copy link
Member

Choose a reason for hiding this comment

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

it is not always the home folder because this can be controlled with environment variables as well. so I think it might be a bit long to explain on the first line of the docstring entry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True in that case but may be valid for other case where the default is None

nilearn/datasets/func.py Outdated Show resolved Hide resolved
nilearn/decoding/decoder.py Outdated Show resolved Hide resolved
nilearn/glm/first_level/first_level.py Outdated Show resolved Hide resolved
nilearn/maskers/multi_nifti_labels_masker.py Outdated Show resolved Hide resolved
nilearn/plotting/html_surface.py Outdated Show resolved Hide resolved
nilearn/regions/region_extractor.py Outdated Show resolved Hide resolved
nilearn/reporting/glm_reporter.py Outdated Show resolved Hide resolved
nilearn/glm/first_level/first_level.py Outdated Show resolved Hide resolved
@bthirion
Copy link
Member

bthirion commented Oct 9, 2023

@bthirion @ymzayek Let me know if you want me to split this PR into several smaller ones to make the review less painful.

No, we have to go through this anyhow. Maybe don't make it too much larger. I'll do a pass once you have addressed @ymzayek 's comments.

Remi-Gau and others added 9 commits October 13, 2023 09:35
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com>
@Remi-Gau Remi-Gau marked this pull request as ready for review October 13, 2023 10:39
nilearn/_utils/data_gen.py Outdated Show resolved Hide resolved
Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

Thx. Very minor things, LGTM otherwise.



if __name__ == "__main__":
main()
Copy link
Member

Choose a reason for hiding this comment

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

When (and by whom) is this script supposed to be run ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Originally I though that this was a script it would be convenient to "keep around" for maintainers to run "once in a while" to ensure that defaults are declared properly.

But after looking around it feels like the one from @mathdugre in the sandbox:

https://github.com/nilearn/nilearn_sandbox/blob/master/nilearn_sandbox/_utils/missing_docstring_default.py

may be adapted to do a better and more systematic job than I put together here for moving defaults.

This should also be discussed in the context of @ymzayek work to mkae type annotation play nice with writing and rendering of the docstrings in #4049

To keep things "simple" I would suggest:

  • move this script to the sandbox for now
  • modify @mathdugre scripts to make sure that all functions / methods with default parameters have those defaults described in the docstring (at least for the public API)
  • cross the bridge about docstring + type annotation when we get to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

move the script to a PR in the sandbox

nilearn/decoding/decoder.py Outdated Show resolved Hide resolved
nilearn/decomposition/_base.py Outdated Show resolved Hide resolved
nilearn/glm/first_level/first_level.py Show resolved Hide resolved
Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM, thx.

@Remi-Gau Remi-Gau merged commit 1f20b65 into nilearn:main Oct 17, 2023
32 checks passed
@Remi-Gau Remi-Gau deleted the default branch October 17, 2023 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants