Skip to content

Use a dataclass instead of a dict as a return type for boxplot() #27788

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Feb 13, 2024

This is a prove of concept. Backward compatibility is achieved though a collections.abc.Mapping mixin. Note though, that I did not go as far as MutableMapping. If someone has written to the returned dict, they would still be broken.

open issues:

  • documentation incomplete
  • should switch usages in the matplotlib code to attributes
  • Where to put the dataclass? cbook or axes?
  • should we use silent_list to make the repr a bit nicer?
    -> not for now. There's value in having a plain list. If we want to improve the repr, rather implement a special repr for BoxplotArtists. But that can be done later.

@timhoffm timhoffm marked this pull request as draft February 13, 2024 23:50
@tacaswell
Copy link
Member

This is an interesting idea!

This also seems to be a step in the right direction for maybe having this object be in the draw tree (rather than all of the parts individually).

We should also put a remove method on it that calls down to all of its children.

@timhoffm
Copy link
Member Author

timhoffm commented Feb 14, 2024

Yes, we could extend this to something like an ArtistContainer, which itself can support (parts of) the Artist API. But let's start small.

@timhoffm timhoffm force-pushed the return-dataclass branch 5 times, most recently from f6cd232 to ef3d7e9 Compare February 16, 2024 11:19
@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Feb 16, 2024
@timhoffm timhoffm force-pushed the return-dataclass branch 2 times, most recently from 0968c26 to 9652073 Compare February 16, 2024 11:27
@timhoffm
Copy link
Member Author

I just realized that we have Container, which could be a complimentary approach. However, I think that a data class is the more simple and understandable approach (-> public concept). Also, I'm not sure we want to buy into the additional functionality ofContainer right now. And finally, the data class and an equivalent Container are API compatible for relevant operations (read-only attribute access). So I don't think adding the dataclass now would render us in an unwanted corner. We could switch to Container later.

@timhoffm timhoffm marked this pull request as ready for review February 16, 2024 12:19
This is a prove of concept. Backward compatibility is achieved though
a collections.abc.Mapping mixin. Note though, that I did not go as far
as MutableMapping. If someone has written to the returned dict, they
would still be broken.

open issues:
- documentation incomplete
- should switch usages in the matplotlib code to attributes
- Where to put the dataclass? cbook or axes?
- should we use silent_list to make the repr a bit nicer?
@timhoffm timhoffm added this to the v3.10.0 milestone Mar 8, 2024
@timhoffm timhoffm marked this pull request as draft March 8, 2024 19:00
@timhoffm
Copy link
Member Author

timhoffm commented Mar 8, 2024

Put to draft to rethink this approach vs. Container. Feedback welcome.

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

Successfully merging this pull request may close these issues.

3 participants