Skip to content

Documentation updates and testing #1038

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

Merged
merged 15 commits into from
Aug 13, 2024

Conversation

murrayrm
Copy link
Member

@murrayrm murrayrm commented Aug 9, 2024

This PR provides updated docstrings for a large number of functions that had undocumented arguments, along with a unit test that checks to make sure that positional arguments and keyword arguments are appropriately documented. The unit test (docstring_test.py) checks for the following:

  • All named arguments should be documented in the docstring using standard Python docstring syntax (parameter name followed by a space, then a colon, then another space).
  • Detectable keyword arguments accessed via **kwargs are also checked to make sure they are documented.
  • Exceptions are allowed to skip testing for entire functions or specific arguments in selected functions.
  • Functions with unnamed positional arguments (*args) must be checked manually and an MD5 hash on the source code is used to make sure that changes will require reconfirmation (by updating the stored hash).
  • Deprecated functions must contain a Sphynx deprecation message and issue a FutureWarning.

Implementing this unit test picked up ~30 undocumented variables that are now documented, as well as triggering a few changes in argument processing and some argument hiding (for internal arguments that the user should never call, which now should start with an underscore).

This PR contains no changes in functionality, just docstring updates and small code changes for consistency (eg, DeprecationWarning [which is ignored/hidden by default] → FutureWarning [which generates a user-visible warning]).

@murrayrm murrayrm mentioned this pull request Aug 9, 2024
11 tasks
@coveralls
Copy link

coveralls commented Aug 9, 2024

Coverage Status

coverage: 94.693% (-0.001%) from 94.694%
when pulling c3ea6dc on murrayrm:doc-comment_fixes-11May2024
into 3d79ce3 on python-control:main.

@slivingston slivingston self-assigned this Aug 11, 2024
@murrayrm murrayrm force-pushed the doc-comment_fixes-11May2024 branch from c9a07c1 to 4ef9dd6 Compare August 11, 2024 21:22
Copy link
Member

@slivingston slivingston left a comment

Choose a reason for hiding this comment

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

I plan to finish review tomorrow.

@@ -220,6 +221,10 @@ def suptitle(
def get_plot_axes(line_array):
"""Get a list of axes from an array of lines.

.. deprecated:: 0.10.1
This function will be removed in a future version of python-control.
Use `cplt.axes` to obtain axes for a control plot `cplt`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Use `cplt.axes` to obtain axes for a control plot `cplt`.
Use `cplt.axes` to obtain axes for an instance of :class:`ControlPlot`.

Even though get_plot_axes() is defined in the same module (ctrlplot) as ControlPlot, it is available at the top of the package as control.get_plot_axes(), so a user may not realize that cplt abbreviates the new class ControlPlot. E.g., observe how get_plot_axes() is shown at https://python-control.readthedocs.io/en/0.10.0/generated/control.get_plot_axes.html.

Therefore, I recommend to be explicit here when referring to the class ControlPlot.

@@ -268,6 +274,9 @@ def pole_zero_subplots(
Scaling to apply to the subplots.
fig : :class:`matplotlib.figure.Figure`
Figure to use for creating subplots.
rcParams : dict
Override the default parameters used for generating plots.
Default is set up config.default['freqplot.rcParams'].
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Default is set up config.default['freqplot.rcParams'].
Default is set up config.default['ctrlplot.rcParams'].

Frequency label (defaults to "rad/sec" or "Hertz")
freq_label, magnitude_label, phase_label : str, optional
Labels to use for the frequency, magnitude, and phase axes.
Defaults are set by `config.defaults['freqplot.<keyword>']`.
Copy link
Member

Choose a reason for hiding this comment

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

I like that descriptions of these parameter are combined, but in this case, magnitude_label and phase_label should be deleted below.

show_legend : bool, optional
Force legend to be shown if ``True`` or hidden if ``False``. If
``None``, then show legend when there is more than one line on an
axis or ``legend_loc`` or ``legend_map`` has been specified.
title : str, optional
Set the title of the plot. Defaults to plot type and system name(s).
title_frame : str, optional
Set the frame of reference used to center the plot title. If set to
'axes' (default), the horizontal position of the title will
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'axes' (default), the horizontal position of the title will
'axes' (default), the horizontal position of the title will be

title_frame : str, optional
Set the frame of reference used to center the plot title. If set to
'axes' (default), the horizontal position of the title will
centered relative to the axes. If set to `figure`, it will be
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
centered relative to the axes. If set to `figure`, it will be
centered relative to the axes. If set to 'figure', it will be

To be consistent with 'axes' and other strings in these parameter descriptions, this should be 'figure' rather than `figure`.

title_frame : str, optional
Set the frame of reference used to center the plot title. If set to
'axes' (default), the horizontal position of the title will
centered relative to the axes. If set to `figure`, it will be
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
centered relative to the axes. If set to `figure`, it will be
centered relative to the axes. If set to 'figure', it will be

To be consistent with 'axes' and other strings in these parameter descriptions, this should be 'figure' rather than figure.

Copy link
Member

@slivingston slivingston left a comment

Choose a reason for hiding this comment

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

Excellent work on the docstrings checker. It seems useful enough to be offered to the numpydoc repository or made into a ruff rule.

I added several more small comments. After considering those, this is ready to merge.

inputs : int, list of str, or None
Description of the system inputs. This can be given as an integer
states : int, list of str, or None
Description of the system states. Same format as `inputs`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Description of the system states. Same format as `inputs`.
Description of the system states. Same format as `outputs`.

For inputs, we have "Same format as outputs." Best to just point from here to outputs (instead of inputs, which in turn points to outputs).

@@ -985,6 +1013,9 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,

"""(legacy) Phase plot for 2D dynamical systems.

.. deprecated:: 0.10.1
This function is deprecated; use `phase_plane_plot` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This function is deprecated; use `phase_plane_plot` instead.
This function is deprecated; use :func:`phase_plane_plot` instead.

Else, Sphinx/numpydoc will not create a link.

@@ -1243,14 +1274,18 @@ def phase_plot(odefun, X=None, Y=None, scale=1, X0=None, T=None,
def box_grid(xlimp, ylimp):
"""box_grid generate list of points on edge of box

.. deprecated:: 0.10.0
Use :func:`phaseplot.boxgrid` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Note that neither boxgrid() nor box_grid() appear in the generated user's manual, so this :func: link is not used anywhere that I observed.

Comment on lines 146 to 149
if f"*{argname}" not in docstring and verbose:
print(f" {name} has positional arguments; "
"check manually")
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if f"*{argname}" not in docstring and verbose:
print(f" {name} has positional arguments; "
"check manually")
warnings.warn(
if f"*{argname}" not in docstring:
if verbose:
print(f" {name} has positional arguments; "
"check manually")
warnings.warn(

This warning message should be sent independently of verbose.

@murrayrm murrayrm merged commit ecf6a38 into python-control:main Aug 13, 2024
12 checks passed
@murrayrm murrayrm deleted the doc-comment_fixes-11May2024 branch August 13, 2024 13:32
@murrayrm murrayrm added this to the 0.10.1 milestone Aug 17, 2024
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.

3 participants