Skip to content
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

ENH: expand call signature of cycler() #12

Closed
WeatherGod opened this issue Aug 20, 2015 · 5 comments
Closed

ENH: expand call signature of cycler() #12

WeatherGod opened this issue Aug 20, 2015 · 5 comments

Comments

@WeatherGod
Copy link
Member

In the discussions going on over in matplotlib/matplotlib#4686, some have asked for the cycler() call signature to be expanded a bit. Now, this can be a rabbit hole, so I will break out the proposal into stages so that we can decide just how deep we want to go:

Current signature (I call this the simple positional):
cycler(key, vals)

  1. Allow a single kwarg to be equivalent to the current notation:
    cycler(k=vals)
    Example:
    cycler(color='rgb') vs.
    cycler('color', 'rgb')

  2. Allow for multiple kwargs (all assumed to be "added" together):
    cycler(k1=v1[, k2=v2, ...])
    Example:
    cycler(color='rgb', lw=[1, 2, 3]) vs.
    cycler('color', 'rgb') + cycler('lw', [1, 2, 3])

  3. Allow for multiple positional args (all assumed to be "multiplied" together):
    cycler(k1, v1[, k2, v2, ...])
    Example:
    cycler('color', 'rgb', 'lw', [1, 2, 3])
    cycler('color', 'rgb') * cycler('lw', [1, 2, 3])

For 2 & 3, I would completely disallow the mixing of positional and keyword arguments.
If we want to avoid having two different operations possible from a single cycler(), we could forgo option 3, and go for the following:
3alt) Allow for both positional and kwargs, but assume all to be "added" together:
cycler(k1, v1[, *args][, k3=v3, **kwargs])

Whichever option (if any) people want, I can put together a PR that implements that. Ideally, I would like to have cycler.cycler() to have very similar, if not identical, call signatures to my validating version that I am making in the matplotlib PR referenced above.

@efiring
Copy link
Member

efiring commented Aug 20, 2015

I think that including #3 makes everything too confusing and hard to remember. #1 and #2 make good sense to me, and I can see #3alt as a reasonable but not essential generalization--and probably not worth the extra complexity in implementation and documentation. I don't see any obvious use case for for which #3alt is advantageous. The use case for #2 is that it facilitates
ax.set_prop_cycle(**kw) as well as ax.set_prop_cycle(color='rgb').

@efiring
Copy link
Member

efiring commented Aug 20, 2015

Can the cycler() signature be modified to accept only the following two signatures?

c = cycler(pre_existing_Cycler_instance)

and

c = cycler(**kw)

In other words, eliminate the present two-argument form as completely unnecessary when the **kw form is available. I don't see any advantages to the two-argument form.

@WeatherGod
Copy link
Member Author

It is still early enough in this project's lifetime to make a complete change like that. It isn't like doing an API change for matplotlib. We can always go back to including positional arguments in the future, if we want it.

@WeatherGod
Copy link
Member Author

note, I could also implement it where multiple positional arguments (more than one pair) would be excluded. (actually, I already have, I just haven't submitted it yet)

@WeatherGod
Copy link
Member Author

Just realized that we would need to update the repr's because they use the positional form. Not terrible, but just an additional thing to complete.

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

No branches or pull requests

2 participants