Skip to content

changing import suggested by tim #27210

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 1 commit into
base: main
Choose a base branch
from

Conversation

EricRLeao1311
Copy link

PR summary

pyplot.cycler and matplotlib.cycler are 2 different cycler functions that can be called. We should not expose two different cycler functions in matplotlib, as this may lead to inconsistencies. Exposing matplotlib.rcsetup.cycler() in pyplot.

PR checklist

@QuLogic
Copy link
Member

QuLogic commented Oct 27, 2023

From the issue:

The main task here is not the code change itself, but to understand the logic and be sure that the change would not break any users.

Did you do that check?

@EricRLeao1311
Copy link
Author

Yes, but since there were some errors, perhaps there was in fact something different in the logic that I missed. The errors they gave were different from my previous PR and do not explicitly show where exactly the error is. I am, again, reviewing the logic and, if I find differences, I will update here.

@EricRLeao1311
Copy link
Author

From what I understand, the code actually validates the arguments passed and then calls the "original" cycler function. First it checks whether the arguments are unique, since the function only has one type of argument (i.e., either just positional arguments or just keyword arguments), but not both. If this is the case, an error is raised. It also checks how many arguments are passed, and depending on the result it performs different validations. If it is just one argument, for example, it checks if the argument type is a 'Cycler', if so, it calls a function called validate_cycler with that object and returns the result. This is a way of copying an already existing Cycler object. All the code, until the last line, is just for validating the arguments passed. The last line was the trickiest to understand for me.

return reduce(operator.add, (ccycler(k, v) for k, v in validated))

From what I understand, it creates a 'Cycler' object that contains their validated values. It does this using the 'reduce' function, which combines the Cycler objects using the addition operation ('operator.add'). It iterates over the list of (k, v) pairs in validated and creates a Cycler object for each pair, then combines them using the addition operation. In this sense, I believe that some test may be failing in this last line, but it seems to me, in fact, the matplotlib.rcsetup cycler just does some validations and after that calls the original cycler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

[MNT]: matplotlib.cycler and pyplot.cycler are different functions
3 participants