Skip to content

Rename ncol parameter in legend to ncols #23198

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

Merged
merged 1 commit into from
Jun 11, 2022
Merged

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Jun 3, 2022

PR Summary

Closes #12078

It seems like only legend uses ncol and that nrow is not used (only nrows).

Will add release note once I get a PR number and I see that I have not missed anything. Done!

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus oscargus changed the title Rename ncol parameter to ncols Rename ncol parameter in legend to ncols Jun 4, 2022
@oscargus oscargus force-pushed the renamencol branch 2 times, most recently from 1b0219e to 7c3d4df Compare June 4, 2022 11:22
@@ -294,6 +294,7 @@ class Legend(Artist):
def __str__(self):
return "Legend"

@_api.rename_parameter("3.6", "ncol", "ncols")
Copy link
Member

Choose a reason for hiding this comment

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

This is very old and pretty heavily used. I am not sure we should deprecate it? Can we just alias it and change the docs to the preferred grammar?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I even make a release note then? Or just let (new) users slowly realize that ncols is the preferred name?

Copy link
Member

Choose a reason for hiding this comment

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

I think a what's new is helpful....

@oscargus oscargus force-pushed the renamencol branch 3 times, most recently from b778f6d to 84882cc Compare June 5, 2022 10:36
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

I think this is at the very border of being worth the trouble.

  • The current usages of ncols are for subplots/gridspec, which is context-wise quite a bit away from legend(), so IMHO the inconsistency is not very obvious.
  • ncol is too prominent for deprecation, which means we'll live forever with duplicate parameters.

If we do this, I suggest to make it explicit as laid out in the comments.

@oscargus
Copy link
Member Author

I think this is at the very border of being worth the trouble.

An option is of course to just close #12078 as won't fix. Should I do that instead?

@jklymak
Copy link
Member

jklymak commented Jun 11, 2022

I'm actually in favour of this change. Sure they are semantically distinct, but having the exact same thing have different short forms is a nuisance ("loc"/"location" also comes to mind) because I can't remember which one belongs to which method.

@oscargus
Copy link
Member Author

oscargus commented Jun 11, 2022

I've merged the suggested changes from @timhoffm Thanks!

Please remember to squash and merge. I had to rebase locally anyway.

Not sure why @timhoffm is left out on the merged commit? Is that a consequence of fixup or anything else?

@oscargus oscargus force-pushed the renamencol branch 2 times, most recently from 1349074 to b9f9205 Compare June 11, 2022 11:39
@jklymak
Copy link
Member

jklymak commented Jun 11, 2022

If you squash you need to keep the "co-authored by" comments in there. Feel free to ping me for a review if I forget in the next few days.

@oscargus
Copy link
Member Author

Ahh, I used fixup, not squeeze... That probably explains it! (Now I realize the use case of squeeze. That always looked a bit useless to me and "covered" by rename and fixup, but clearly not in this case.)

@jklymak
Copy link
Member

jklymak commented Jun 11, 2022

I'm not sure what fixup or squeeze are. I always just do an interactive rebase (rebase -i upstream/main).

@oscargus
Copy link
Member Author

fixup and squeeze are the things you can write in front of commits when doing the interactive rebase.

@jklymak
Copy link
Member

jklymak commented Jun 11, 2022

Ah squeeze=squash ;-)

@@ -333,6 +336,8 @@ def __init__(
frameon=None, # draw frame
handler_map=None,
title_fontproperties=None, # properties for the legend title
*,
ncol=1 # synonym for ncols (backward compatibility)
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this? I think you have to leave ncol where it was for backcompat? We should prob move all of these to kwarg only...

Copy link
Member Author

Choose a reason for hiding this comment

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

If someone uses this with a positional argument it will be picked up as ncols, so that should be fine. ncols will also come earlier when editors pop up the list of arguments, so I think this is really the way to go.

As #23166 is in, we are on the way to keyword only arguments.

Copy link
Member

Choose a reason for hiding this comment

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

Oops yes I agree.

@jklymak jklymak merged commit 92893d8 into matplotlib:main Jun 11, 2022
@oscargus oscargus deleted the renamencol branch June 11, 2022 20:26
@QuLogic QuLogic added this to the v3.6.0 milestone Jun 14, 2022
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.

Inconsistency in keyword-arguments ncol/ncols, nrow/nrows
4 participants