Skip to content

Drop the bins entry from plot_param_updates' docstring - #1155

Merged
BenjaminBossan merged 3 commits into
skorch-dev:masterfrom
VenishPaneliya:doctor-phantom-bins
Sep 22, 2026
Merged

BenjaminBossan merged 3 commits into
skorch-dev:masterfrom
VenishPaneliya:doctor-phantom-bins

Conversation

@VenishPaneliya

Copy link
Copy Markdown
Contributor

SkorchDoctor.plot_param_updates documents a bins parameter it doesn't accept:

def plot_param_updates(self, match_fn=None, axes=None, figsize=None, **kwargs):
        bins : np.ndarray or None (default=None)
          Bins to use for the histogram. If left as ``None``, they are inferred
          from the data.

It's a line plot of relative parameter updates over time, not a histogram, so there are no bins to configure. The entry looks carried over from the methods that genuinely have it — plot_activations, plot_gradients, plot_activations_over_time and plot_gradient_over_time all take a real bins argument and use it for np.linspace(...). plot_param_updates is the only one of the six that documents it without having it.

Following the docstring doesn't just get ignored, it fails: bins falls through **kwargs into ax.plot(xvec, values, label=key, **kwargs), and matplotlib rejects it.

>>> ax.plot(np.arange(3), np.arange(3), label="x", bins=None)
AttributeError: Line2D.set() got an unexpected keyword argument 'bins'

Docs only — just the four lines removed, no code touched. skorch/tests/test_doctor.py passes (42 tests).

One thing I left alone: the **kwargs entry here (and in the sibling plot methods) describes figsize as something you override through **kwargs, even though figsize is an explicit parameter in each of those signatures. That's consistent across the methods, so it reads like a deliberate house phrasing rather than a mistake, and I didn't want to churn several docstrings on my own reading of it. Happy to tidy that up separately if you'd like it changed.

I also skipped a CHANGES.md entry since this doesn't change behaviour — let me know if you'd prefer one under Fixed.

`SkorchDoctor.plot_param_updates` documents a `bins` parameter it does
not accept. It is a line plot over time, not a histogram, so there are no
bins to configure - the entry was carried over from the histogram methods
(`plot_activations`, `plot_gradients` and the two *_over_time plots),
which all really do take `bins`.

Following the docstring fails: `bins` falls through `**kwargs` into
`ax.plot`, which raises
`AttributeError: Line2D.set() got an unexpected keyword argument 'bins'`.

@BenjaminBossan BenjaminBossan left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing the docstring, including "bins" there was indeed a mistake.

One thing I left alone: the **kwargs entry here (and in the sibling plot methods) describes figsize as something you override through **kwargs, even though figsize is an explicit parameter in each of those signatures.

This was certainly not intentional, more of an oversight. I think it would make sense to mention another argument there instead of "figsize", something like "lw" (line width). If you're up to it, please update the docstrings there as well.

The **kwargs entries offered `figsize` as an example, but `figsize` is an
explicit parameter of every one of these methods, so it never reaches
**kwargs. Replaced it per method with an argument that does, chosen against
what each method already forwards:

  plot_activations / plot_gradients   -> alpha      (ax.hist already gets
                                                     histtype, lw, bins, density)
  plot_param_updates                  -> lw         (ax.plot gets only label)
  plot_activations_over_time /
  plot_gradient_over_time             -> linestyle  (fill_between already gets
                                                     alpha, color, lw)

`lw` works for plot_param_updates but not for the histogram methods: passing
it through **kwargs there raises "got multiple values for keyword argument
'lw'", which is the same class of mistake as the `figsize` mention.
@VenishPaneliya

Copy link
Copy Markdown
Contributor Author

Done — though lw turned out to only be safe in one of them, so I picked per method based on what each one already forwards.

plot_activations and plot_gradients pass lw explicitly into ax.hist (along with histtype, bins, density), so suggesting lw there would land users in the same trap as figsize:

>>> ax.hist(y, label=k, histtype='step', lw=2, bins=5, density=True, **{'lw': 3})
TypeError: Axes.hist() got multiple values for keyword argument 'lw'

So:

method forwards to already passes example now used
plot_activations, plot_gradients ax.hist histtype, lw, bins, density alpha
plot_param_updates ax.plot label lw
plot_activations_over_time, plot_gradient_over_time ax.fill_between alpha, color, lw linestyle

I checked each replacement actually goes through rather than assuming — alpha on hist, lw on plot and linestyle on fill_between all work, and alpha on fill_between raises the same duplicate-keyword error, which is why the two *_over_time methods got linestyle instead.

skorch/tests/test_doctor.py still passes (42 tests). The rewrap also happens to fix one pre-existing E501 on the old figsize line; the three flake8 warnings left in that file are on untouched lines and are present on master too.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. I went through the docstrings again and found that the arguments are still very inconsistently documented. Ideally, we would have documentation exactly for the arguments that are indeed present. So as an example, in plot_gradient_over_time, lw, figsize, and color are not documented. Is that something you'd like to tackle?

Following up on review: the plot methods documented only some of their
parameters. Added the missing entries so each Parameters section matches
its signature exactly.

  plot_loss                   had no Parameters section at all
                              (ax, figsize, **kwargs) plus a Returns section
  plot_activations            histtype, lw, density, figsize
  plot_gradients              histtype, lw, density, figsize
  plot_param_updates          figsize
  plot_activations_over_time  lw, figsize, color
  plot_gradient_over_time     lw, figsize, color

All six now document exactly the arguments present, no more and no fewer.
@VenishPaneliya

Copy link
Copy Markdown
Contributor Author

Happy to — done. Every plot method now documents exactly the arguments it takes.

method added
plot_loss had no Parameters section at all — added ax, figsize, **kwargs, plus a Returns section to match its siblings
plot_activations histtype, lw, density, figsize
plot_gradients histtype, lw, density, figsize
plot_param_updates figsize
plot_activations_over_time lw, figsize, color
plot_gradient_over_time lw, figsize, color

I checked it both directions rather than by eye — comparing each signature against its parsed Parameters section, there are now no missing entries and no documented-but-absent ones across all six. numpydoc also parses each of them with zero warnings, and the parameter counts line up with the signatures (e.g. plot_activations → 9).

One small wording note: I described figsize as "only used when a new plot is created, i.e. when axes is None", since _get_axes returns the passed axes untouched and ignores figsize in that case — that seemed worth stating explicitly, but say the word if you'd rather keep it shorter.

skorch/tests/test_doctor.py passes (42 tests), and flake8 output on the file is unchanged from master.

@VenishPaneliya

Copy link
Copy Markdown
Contributor Author

Note on the red CI: the failures are the model-convergence assertions (assert 0.71 > 0.75, assert np.float64(7.85) < 1.0), and they show up across Python 3.10 / 3.11 / 3.13 and several torch builds in the same run. This PR changes only docstring text in skorch/_doctor.py (1 file, no code lines), so it can't affect training accuracy — looks like flakiness rather than anything from here. Happy to rebase if you'd like a clean run.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for bringing all the docstrings in line, LGTM.

@BenjaminBossan
BenjaminBossan merged commit 195afc0 into skorch-dev:master Sep 22, 2026
31 of 32 checks passed
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