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

Docstring cleanup: "default None", doi #1828

Merged
merged 29 commits into from
Dec 12, 2023

Conversation

echedey-ls
Copy link
Contributor

@echedey-ls echedey-ls commented Aug 4, 2023

  • Closes "default None" in docstring parameter descriptions considered harmful #1574 . All changes at the bottom.
  • I am familiar with the contributing guidelines
  • [ ] Tests added
  • [ ] Updates entries in docs/sphinx/source/reference for API changes.
  • [ ] Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • Current code includes numpydoc compliant docstrings, examples, and comments everywhere.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

Cherry-picked commits from #1790 and repeated the process with the regexes, with little changes to them.

Changes in this PR

  1. Changes excessive use of parentheses in defaults
    return_components: bool (optional, default=False) -> return_components : bool, default False
  2. default None -> optional ("default None" in docstring parameter descriptions considered harmful #1574)
  3. If None -> If not specified
  4. Inexistent DOI roles are now roles, e. g.: DOI: 10... -> :doi:`10...`

Exclude .*=| from negative lookahead

^(\s{8}|\s{4})(?!try|else|doi|DOI|Warning|Access|Requests|Note)(\w*): (?!.*:)(.+)$

Reason: just this line 🌝
Remaining matches are type annotations in modelchain.py and pvsystem.py
@echedey-ls echedey-ls mentioned this pull request Aug 4, 2023
5 tasks
F: (?<spaces>\s{8}|\s{4})(?<name>\w*)\s?: (?<type>.*) \(optional, default=(?<default>.*)\)$
R:
1st-F: (?<spaces> {8}| {4})(?<name>\w*) : (?<types>.*), default None$
2nd-F: (?<spaces> {8}| {4})(?<name>\w*) : [Nn}one or (?<type>.*), optional$
3rd-F: (?<spaces> {8}| {4})(?<name>\w*) : (?<type>.*) or [nN]one, optional$

R: $1$2 : $3, optional
F: If None,
R: If not specified,
F: If None
R: If not specified,
@echedey-ls echedey-ls marked this pull request as ready for review August 6, 2023 20:52
@echedey-ls
Copy link
Contributor Author

echedey-ls commented Sep 30, 2023

regex DOI: ... to :doi:`...`

Done!

Regex find: (?:doi|DOI):(?!`)\s?(.*?)(\.\n|\n)
Replace: :doi:`$1`$2
Copy link
Member

@cwhanse cwhanse left a comment

Choose a reason for hiding this comment

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

Thanks @echedey-ls

There's more markdown to be done in the descriptions of parameters this touches, if you feel it is in scope. I stopped suggesting it.

@pvlib/pvlib-maintainer it is questionable in my mind whether module_parameters, inverter_parameters and the like should be optional for instantiating a ModelChain. The ModelChain is created, true, but nothing runs.

pvlib/clearsky.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/tmy.py Outdated Show resolved Hide resolved
pvlib/modelchain.py Outdated Show resolved Hide resolved
pvlib/modelchain.py Outdated Show resolved Hide resolved
pvlib/pvsystem.py Outdated Show resolved Hide resolved
pvlib/pvsystem.py Outdated Show resolved Hide resolved
pvlib/pvsystem.py Outdated Show resolved Hide resolved
echedey-ls and others added 12 commits October 31, 2023 12:27
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
F: (?<spaces> {8}| {4})(?<name>\w*) : [Nn]one[ ,]*(?<type>.*), optional$
R: $1$2 : $3, optional
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
Co-Authored-By: Cliff Hansen <5393711+cwhanse@users.noreply.github.com>
F1: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<type>.*), default: None
F2: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<types>.*), default None$
F3: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one or (?<type>.*), optional$     zero results
F4: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<type>.*) or [nN]one, optional$     zero results

R: $1$2 : $3, optional
@cwhanse
Copy link
Member

cwhanse commented Oct 31, 2023

@echedey-ls thanks for the work on this. If we don't get all instances of default None in this PR, we can do more later.

F: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<type>.*), default:? None\.?
R: $1$2 : $3, optional

F: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one, (?<type>.*), default:? (?<def>.*)\.?
R: $1$2 : $3, default $4

F: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one or (?<types>.*)
R: $1$2 : $3

F: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<types>.*) or [Nn]one(?<trailing>.*)
R: $1$2 : $3$4

F: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one(?:,|or) (?<types>.*)
R: $1$2 : $3
@echedey-ls
Copy link
Contributor Author

I had to iterate a bit more... At first glance I thought very constraining regexes were enough, but even trailing dots were messing with that. I think all have been addressed for now.

pvlib/iam.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/iotools/pvgis.py Outdated Show resolved Hide resolved
pvlib/irradiance.py Outdated Show resolved Hide resolved
pvlib/irradiance.py Outdated Show resolved Hide resolved
pvlib/irradiance.py Outdated Show resolved Hide resolved
pvlib/location.py Outdated Show resolved Hide resolved
pvlib/solarposition.py Outdated Show resolved Hide resolved
echedey-ls and others added 3 commits November 2, 2023 15:19
pvlib/irradiance.py Outdated Show resolved Hide resolved
pvlib/irradiance.py Outdated Show resolved Hide resolved
echedey-ls and others added 2 commits November 2, 2023 23:17
Co-authored-by: Cliff Hansen <cwhanse@sandia.gov>
@echedey-ls
Copy link
Contributor Author

This should be ready to go, unless anything else wants to be done!

Copy link
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @echedey-ls! Might be worth leaving a comment on this PR with a list of the final set of regexes you used for this PR, in case we want to re-run something like this in the future.

it is questionable in my mind whether module_parameters, inverter_parameters and the like should be optional for instantiating a ModelChain. The ModelChain is created, true, but nothing runs.

@cwhanse I'm not sure what you mean. ModelChain doesn't take module_parameters or inverter_parameters.

@echedey-ls
Copy link
Contributor Author

None regexes

These go by order:
F: (?<spaces>\s{8}|\s{4})(?<name>\w*)\s?: (?<type>.*) \(optional, default=(?<default>.*)\)$
Manually fix every match. This is a very constraining regex.

F1: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<type>.*), default:? None\.?
F2: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one(?:,| or) (?<types>.*)
F3: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<type>.*) or [nN]one, optional
R: $1$2 : $3, optional
Note: F3 requires special attention to commas.

F: (?<spaces> {8}| {4})(?<name>\w*) ?: [Nn]one, (?<type>.*), default:? (?<def>.*)\.?
R: $1$2 : $3, default $4

F: (?<spaces> {8}| {4})(?<name>\w*) ?: (?<types>.*) or [Nn]one(?<trailing>.*)
R: $1$2 : $3$4

F: If None
R: If not specified,

DOI regexes:

Regex find: (?:doi|DOI):(?!`)\s?(.*?)(\.\n|\n)
Replace: :doi:`$1`$2

Some of them could be changed to be more flexible, but I wanted the least number of false positives. I'm looking at the excessive-parentheses regex, they are really ugly in the web.

@cwhanse cwhanse mentioned this pull request Dec 8, 2023
15 tasks
@kandersolar
Copy link
Member

With no objections, time to merge! Thanks again @echedey-ls :)

@kandersolar kandersolar changed the title Refactor docstring params (2) Docstring cleanup: "default None", doi Dec 12, 2023
@kandersolar kandersolar merged commit 300aedc into pvlib:main Dec 12, 2023
30 checks passed
@echedey-ls echedey-ls deleted the refactor-docstring-params-2 branch December 12, 2023 16:57
@echedey-ls echedey-ls mentioned this pull request Jun 10, 2024
3 tasks
@echedey-ls echedey-ls mentioned this pull request Jul 19, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"default None" in docstring parameter descriptions considered harmful
3 participants