Skip to content

Add consistency check for PathCollection sizes and edgecolors (#28833) #30138

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BrunoWolf03
Copy link

This pull request addresses issue #28833 by adding a consistency check in PathCollection.

The new check_consistency() method emits a UserWarning if the number of sizes or edgecolors
does not match the number of paths. This method is called during the draw() call to catch any
inconsistencies before rendering.

A test (test_pathcollection_size_mismatch_warning) is included to validate the warning behavior.

==================================================================

…tlib#28833)

This patch adds a check_consistency() method to PathCollection,
which emits a warning if the number of sizes or edgecolors does not
match the number of paths. The check is invoked during the draw()
call to ensure it happens after all data is set.

Also adds a unit test that triggers the warning for mismatched sizes.
Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

Thank you for the potential contribution. I think for now the main aim of the issue is to decide what we want to happen, so there is no guarantee this will get merged even if it works perfectly.

UserWarning: Number of sizes does not match number of paths.
"""
n_paths = len(self.get_paths())
if self._sizes is not None and len(self._sizes) not in (1, n_paths):
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 self._sizes is not None and len(self._sizes) not in (1, n_paths):
if self._sizes.size not in (0, 1, n_paths):

Looking at the set_sizes method, we always end up with an array here, though it may be size zero (if None was passed). I think this is the cause of at least some of the failing tests (any warnings are translated into errors in the tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MNT]: Data size consistency checks in _CollectionsWithSizes
2 participants