Skip to content

fix(matplotlib): corriger le rendu des histogrammes adaptatifs - #35

Open
ElouenGinat wants to merge 18 commits into
mainfrom
fix/matplotlib-hist-regressions-34
Open

ElouenGinat wants to merge 18 commits into
mainfrom
fix/matplotlib-hist-regressions-34

Conversation

@ElouenGinat

@ElouenGinat ElouenGinat commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • Preserve Khiops frequencies and keep narrow adaptive bins visible.
  • Reject unsupported histtype="barstacked".
  • Export hist from the package root and infer its return type from histtype.
  • Simplify the demo, use root-level imports, and refresh its figures.

Validation

  • uv run pytest -q
  • Demo notebook executed end to end
  • uv run sphinx-build -W --keep-going -b html docs docs/_build/html
  • Pre-commit hooks

Closes #34

Réutiliser les fréquences Khiops pour les valeurs extrêmes et rendre visibles les classes très étroites par défaut. Refuser également le type barstacked non pris en charge.

Closes #34
@ElouenGinat ElouenGinat linked an issue Sep 22, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://KhiopsML.github.io/khisto-python/pr-preview/pr-35/

Built to branch gh-pages at 2026-09-28 07:50 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@ElouenGinat
ElouenGinat requested review from marcboulle and popescu-v and a lite review from Copilot and removed request for marcboulle September 22, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The cumulative density implementation, ec edge styling, and stale notebook import remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Updates the Matplotlib histogram adapter to preserve Khiops frequencies, improve adaptive-bin rendering, and expose hist at the package root.

Changes:

  • Adds typed histogram returns and rejects unsupported stacked histograms.
  • Updates plotting behavior, tests, documentation, CI, changelog, and demo metadata.
File Summary
tests/​plot/​test_matplotlib_histogram.py Adds histogram behavior and typing tests.
src/​khisto/​matplotlib/​hist.py Implements frequency-backed plotting and return handling; cumulative density behavior and ec styling require changes.
src/​khisto/​__init__.py Exports hist at the package root.
sandbox/​khisto_demo.ipynb Updates demo metadata; retains a stale _hist import that causes an import error.
pyproject.toml Adds the Python 3.10 typing dependency.
docs/​index.rst Updates usage examples.
docs/​conf.py Configures Matplotlib API documentation.
docs/​api_comparison.md Documents unsupported histogram options.
CHANGELOG.md Records the histogram changes.
.github/​workflows/​ci.yaml Adds optional-dependency installation coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/khisto/matplotlib/hist.py Outdated
Comment thread src/khisto/matplotlib/hist.py Outdated
ElouenGinat and others added 2 commits September 22, 2026 16:20
…ct for unequal-width bins'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@marcboulle marcboulle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

J'ai bien aimé la simplification de la démo ;)

Pour le reste, je n'ai fait que survolé le code rapidement. Je ne comprend pas tous les détails et le pourquoi des évolutions. C'est suite aux retours utilisateurs? ou à des tests approfondis?

J'ai quelques remarques et surtout des questions de détail.

Comment thread docs/demo.ipynb Outdated
Comment thread docs/demo.ipynb
Comment thread src/khisto/matplotlib/hist.py Outdated
Comment thread src/khisto/matplotlib/hist.py
Comment thread .github/workflows/ci.yaml Outdated

- name: Test base API without optional dependencies
run: |
uv run --isolated --no-project --with . python - <<'PY'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would put this Python snippet in a separate script for easier maintenance.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread src/khisto/matplotlib/hist.py Outdated
elif isinstance(patches, list):
histogram_patches = [patch for patch in patches if isinstance(patch, Polygon)]
if len(histogram_patches) != len(patches):
raise TypeError("Matplotlib returned unexpected histogram patches.")

@popescu-v popescu-v Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be more specific on the error message:

unexpected_patches = [
    patch for patch in patches if not isinstance(path, Polygon)
]
...
raise TypeError(
    f"Matplotlib returned unexpected histogram patches: {len(unexpected_patches)}"
    f" of them are of types {', '.join(set([type(patch) for patch in unexpected_patches])}."
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

the patches are all of type Polygon or all of type BarContainer. I made the message clearer but i didn't listed all the patches in the message.

Comment thread src/khisto/matplotlib/hist.py Outdated
if len(histogram_patches) != len(patches):
raise TypeError("Matplotlib returned unexpected histogram patches.")
else:
raise TypeError("Matplotlib returned unexpected histogram patches.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be more specific in the message here as well, specifying the type(patches) therein.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread src/khisto/matplotlib/hist.py Outdated
else:
raise TypeError("Matplotlib returned unexpected histogram patches.")

if histtype == "bar" and not {"edgecolor", "ec"} & kwargs.keys():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For more readability, I'd write this if as:

if histtype == "bar" and not {"edgecolor", "ec"}.intersection(kwargs.keys()):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment thread tests/plot/test_matplotlib_histogram.py Outdated
@@ -6,11 +6,20 @@

from __future__ import annotations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to treat typing hints as strings here? Their eager evaluation as objects is not adequate here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

i removed it

Un pyproject.toml étranger présent dans site-packages faisait planter l'import de khisto (fichier ouvert en mode texte). Le pyproject.toml du dépôt n'est désormais lu que si le paquet n'est pas installé.
Commente l'intention (rendre visibles les classes plus fines qu'un pixel) et précise le message d'erreur sur les patches inattendus.

@marcboulle marcboulle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cela me parait bien, en tout cas d'un point de vue fonctionnel.

Un point de détail sur le CHANGELOG, à améliorer éventuellement.

Pour les tests unitaires et de non régression, je fais confiance au mainteneur.

Comment thread CHANGELOG.md

This branch has not been deployed

No deployments
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.

Fix invisible narrow bins and incorrect extreme-value counts

4 participants