Skip to content

fix(matplotlib): preserve Khiops right-closed bins - #33

Merged
ElouenGinat merged 9 commits into
mainfrom
fix/matplotlib-bin-boundaries
Sep 15, 2026
Merged

ElouenGinat merged 9 commits into
mainfrom
fix/matplotlib-bin-boundaries

Conversation

@ElouenGinat

@ElouenGinat ElouenGinat commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

What

  • Shift observations passed to Axes.hist one ULP toward -inf.
  • Preserve the native boundaries returned by Khiops.
  • Add a concise note to the API docstring.
  • Add count and density regression coverage for observations exactly on internal boundaries.

Why

Khiops uses (lower, upper] intervals, while Matplotlib uses [lower, upper). Without an adaptation, a value equal to an internal boundary is displayed in the neighboring interval, and the plotted density can differ substantially from the density computed by Khiops.

Refs #32

This PR fixes Matplotlib rendering. It does not yet modify boundaries returned by khisto.histogram: the NumPy compatibility strategy remains to be decided in the issue so that native HistogramResult data is preserved and floating-point edge cases are handled correctly.

How to test

uv run pytest -o addopts='' tests/plot/test_matplotlib_histogram.py -q
uv run ruff check src/khisto/matplotlib/hist.py tests/plot/test_matplotlib_histogram.py
uv run ruff format --check src/khisto/matplotlib/hist.py tests/plot/test_matplotlib_histogram.py
uv run pre-commit run --all-files

Local result: 19 tests passed and all hooks succeeded.

Documentation preview

Documentation preview

@ElouenGinat
ElouenGinat force-pushed the fix/matplotlib-bin-boundaries branch from f46db29 to 8102a0b Compare September 11, 2026 16:55
@ElouenGinat ElouenGinat changed the title fix(matplotlib): respecter les bornes fermées de Khiops fix(matplotlib): preserve Khiops right-closed bins Sep 11, 2026
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-15 12:14 UTC

@ElouenGinat
ElouenGinat requested review from marcboulle and removed request for marcboulle September 14, 2026 13:47

@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.

Petits changement dans les commentaires.

Je n'ai pas vérifier que l'histogramme retourné est toujours au maximum le plus interprétable.
Est-ce bien le cas avec ton exemple?

Comment thread src/khisto/matplotlib/hist.py Outdated

Notes
-----
Khiops bins are right-closed, ``(lower, upper]``, while Matplotlib bins are

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Etre plus laconique, plus orienté fonctionnalité (en masquant les détail d'implémentation):
"Khiops bins are right-closed, (lower, upper] , unlike Matplotlib bins which are left-closed [lower, upper), but the displayed plot is still correct."

Pour les autres fonctionq de l'API, utiliser une note concise très similaire:
"Khiops bins are right-closed, (lower, upper] , unlike Numpy bins which are left-closed [lower, upper)."

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. Yes the finest histogram (after best) is not returned by the histogram nor the hist functions.

@ElouenGinat
ElouenGinat marked this pull request as ready for review September 14, 2026 16:33

@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.

Concernant les warnings, je pense que l'on peut les passer en notes:

Concernant la PR précédente que tu as mergée:

  • je l'avais approuvée, mais avec des remarques de de détail à prendre en compte (plus un review de Vladimir)
  • je crois tu l'as mergée directement: pourrais tu ici prendre en compte les remarques de cette PR?

Pourrais-tu rebaser ta branche sur main pour pouvoir visualiser le nouveau site complet?

As-tu tester ta correction sur ton jeu de donnée à 6 valeurs entières (avec histogramme pathologique avant les correction)?

@ElouenGinat
ElouenGinat force-pushed the fix/matplotlib-bin-boundaries branch from bfe3af0 to 6433b0c Compare September 15, 2026 07:35
@ElouenGinat

Copy link
Copy Markdown
Collaborator Author

J’ai rebasé la branche sur main et mis à jour la PR. Le site de doc complet est désormais visible dans la preview. J’ai également pris en compte les remarques restantes.
Oui j'ai check que la correction réglait le problème sur le jeu de données à 6 valeurs.

Comment thread src/khisto/core/backend.py Outdated
Comment thread src/khisto/core/backend.py Outdated
Comment thread src/khisto/matplotlib/hist.py Outdated
Comment thread src/khisto/histogram.py Outdated
Comment thread src/khisto/histogram.py Outdated
Comment thread tests/array/test_histogram.py Outdated
Comment thread tests/array/test_histogram.py Outdated
Comment thread tests/plot/test_matplotlib_histogram.py Outdated

@popescu-v popescu-v 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.

Some stylistic comments.
But also a potential leak in case of failure in tests (see comment in point).

@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.

LGTM

@popescu-v popescu-v 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.

LGTM

@ElouenGinat
ElouenGinat merged commit 76d6c49 into main Sep 15, 2026
18 checks passed
@ElouenGinat
ElouenGinat deleted the fix/matplotlib-bin-boundaries branch September 15, 2026 12:14
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