Skip to content

fix: Histogram.plot(type='ncdf') never actually worked, docstring lied - #85

Open
petercorke wants to merge 4 commits into
mainfrom
fix/histogram-plot-ncdf-alias
Open

fix: Histogram.plot(type='ncdf') never actually worked, docstring lied#85
petercorke wants to merge 4 commits into
mainfrom
fix/histogram-plot-ncdf-alias

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Resolves #39.

  • plot()'s docstring claimed 'ncdf' was an accepted type value, but the dispatch logic in _compute_plot_series() only ever handled 'frequency', 'pdf'/'probability', 'cf'/'cumulative', 'cdf'/'normalized' -- 'ncdf' always fell through to raise ValueError("unknown type").
  • Resolution (settles the open question in Histogram.plot's type docstring doesn't match its actual accepted values #39): 'ncdf' (normalized CDF) is what 'cdf'/'normalized' already means today -- a real CDF is normalized by definition, so the naming was simplified rather than the option being dropped by accident. This matches the existing Histogram.ncdf property, which is already a deprecated alias for .cdf with the identical pattern.
  • Added 'ncdf' as a matching deprecated string alias for type='cdf' in plot(), warning and normalizing before dispatch (same DeprecationWarning + stacklevel=2 pattern already used for plot()'s bar= parameter, right above it in the same method).
  • Fixed the docstring (both the :param: line and the prose) to list the real accepted values.
  • Changed type's annotation from plain str to a Literal enumerating the real values (including 'ncdf' as a still-valid deprecated input) -- the exact resolution Histogram.plot's type docstring doesn't match its actual accepted values #39 itself suggested once the docstring/behavior mismatch was settled.

Found while working through RVC3-python's chap11.ipynb, which calls h.plot("ncdf", color="blue") per the printed book.

Test plan

  • New regression test: type='ncdf' warns (DeprecationWarning) and produces the same plot as type='cdf'; fails against pre-fix code with the original ValueError: unknown type
  • Full tests/test_image_whole_features.py suite passes (39 passed)

plot()'s docstring claimed 'ncdf' was an accepted type value, but the
dispatch logic in _compute_plot_series() only ever handled
'frequency', 'pdf'/'probability', 'cf'/'cumulative', 'cdf'/
'normalized' -- 'ncdf' always fell through to
raise ValueError("unknown type"). Filed as tech-debt issue #39.

Resolution: 'ncdf' (normalized CDF) is what 'cdf'/'normalized'
already means today -- a real CDF is normalized by definition, so the
naming was simplified rather than the option being dropped by
accident. This matches the existing Histogram.ncdf *property*, which
is already a deprecated alias for .cdf with the same pattern.

Added 'ncdf' as a matching deprecated string alias for
type='cdf' in plot(), warning and normalizing before dispatch (same
DeprecationWarning + stacklevel=2 pattern already used for plot()'s
bar= parameter, right above it). Also fixed the docstring (both the
:param: line and the prose) to list the real accepted values, and
changed type's annotation from plain str to a Literal enumerating
them, per the tech-debt issue's own suggested resolution.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

Histogram.plot's type docstring doesn't match its actual accepted values

1 participant