Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Offsetbox default arguments #24652

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 15 commits into from
Dec 14, 2022
Merged

Conversation

Ali-Msk
Copy link
Contributor

@Ali-Msk Ali-Msk commented Dec 7, 2022

PR Summary

Closes #24623

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Copy link

@github-actions github-actions bot 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 opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@jklymak
Copy link
Member

jklymak commented Dec 7, 2022

Thanks for the PR! For ease of review, suggest a description of the change and moving the issues from title to the description.

@@ -369,12 +369,12 @@ def draw(self, renderer):


class PackerBase(OffsetBox):
def __init__(self, pad=None, sep=None, width=None, height=None,
def __init__(self, pad=0., sep=None, width=None, height=None,
Copy link
Member

@oscargus oscargus Dec 7, 2022

Choose a reason for hiding this comment

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

I think the same problem holds for sep as well?

Edited: width and height are calculated, but sep must be set.

align="baseline", mode="fixed", children=None):
"""
Parameters
----------
pad : float, optional
pad : float, required
Copy link
Member

Choose a reason for hiding this comment

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

It is still optional, just that it has a correct default now.

@oscargus
Copy link
Member

oscargus commented Dec 7, 2022

Can you please how the outcome of the example code in #24620? Ideally as an image test, but if nothing else just paste the result here.

try:
pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True)
except:
raise Exception("incorrect default value")
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to do this in a test. The test will fail if there is an exception anyway, so skip the try-except.

You can add a comment like

# smoke test for correct default value though

@Skhaki18
Copy link
Contributor

Skhaki18 commented Dec 7, 2022

Plot

This was our result when running the code from 24620 with the default padding of 0. Additionally, we can see the result for padding=5 below:

Plot2

@jklymak jklymak changed the title [#24623][#24620] Offsetbox arguments and incorrect location Offsetbox arguments and incorrect location Dec 7, 2022
@jklymak jklymak added status: needs tests status: needs clarification Issues that need more information to resolve. labels Dec 7, 2022
@jklymak
Copy link
Member

jklymak commented Dec 7, 2022

I'm moving this to draft. Feel free to move back when ready for review.

@jklymak jklymak marked this pull request as draft December 7, 2022 16:46
@oscargus
Copy link
Member

oscargus commented Dec 8, 2022

There is an update in #24620 which shows that PaddedBox is indeed working. And it looks like the proposed solution is not fully handling it.

Hence, my suggestion is to drop the location changes and just go with the default argument ones.

@Krutarth-P
Copy link
Contributor

There is an update in #24620 which shows that PaddedBox is indeed working. And it looks like the proposed solution is not fully handling it.

Hence, my suggestion is to drop the location changes and just go with the default argument ones.

We have made the changes according to your request to use the default values. Would you know how to resolve the CircleCi errors?

@oscargus
Copy link
Member

oscargus commented Dec 9, 2022

The Circle CI issue is a bit weird. It it not related to the contents of your PR anyway. I think I've seen some issue recently where a particular user couldn't run the tests and the best guess was that the GitHub user name was changed. Would that possibly be the case here? Has anyone of you changed GitHub user name after you created your account?

@Krutarth-P
Copy link
Contributor

The Circle CI issue is a bit weird. It it not related to the contents of your PR anyway. I think I've seen some issue recently where a particular user couldn't run the tests and the best guess was that the GitHub user name was changed. Would that possibly be the case here? Has anyone of you changed GitHub user name after you created your account?

change of name doesn't seem to be the case here. any other possible reasons for the error?

@Krutarth-P
Copy link
Contributor

@oscargus @jklymak the builds are successful. We are ready for a review

@rcomer rcomer marked this pull request as ready for review December 11, 2022 08:18
Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Just some minor comments. The testing is good to get correct though.

One may consider changing optional to default: 0.0 in the doc strings. (Or add Default: 0.0. to the description, but I think the first is preferred.)

# smoke test for correct default value though
fig, ax = plt.subplots()
at = AnchoredText("foo", 'upper left')
pb = PaddedBox(at, patch_attrs={'facecolor': 'r'}, draw_frame=True)
Copy link
Member

Choose a reason for hiding this comment

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

This test passes on main as well. (As the fact that pad is None is not a problem until later on.)

You need to do:

ax.add_artist(pb)
fig.draw_without_rendering()

If you can also add a similar thing for one of the packers that would be great! Can go in the same test/figure. There is a previous test for the packers that you can just copy the relevant code from, but leave the pad and sep arguments out.

@Skhaki18
Copy link
Contributor

Skhaki18 commented Dec 14, 2022

@oscargus and @rcomer , We have addressed the requested comments and added the necessary tests. We are able to build successfully and are ready for the next step in merging.

Copy link
Member

@oscargus oscargus left a comment

Choose a reason for hiding this comment

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

Thanks!

I guess this is good to go now. The addition of HPacker/VPacker tests is maybe not so clear, but it will work and test what is expected.

An better option is to simply remove the two previous lines where pad and sep are set as they are now redundant.

Whoever merges this: please squash the commits. (I take it that you are using the web-based interface for editing the files?)

@oscargus oscargus removed status: needs clarification Issues that need more information to resolve. status: needs tests labels Dec 14, 2022
@oscargus oscargus changed the title Offsetbox arguments and incorrect location Offsetbox default arguments Dec 14, 2022
@timhoffm
Copy link
Member

An better option is to simply remove the two previous lines where pad and sep are set as they are now redundant.
r editing the files?)

I took the liberty to commit this change.

@timhoffm timhoffm added this to the v3.7.0 milestone Dec 14, 2022
@timhoffm timhoffm merged commit 58de4e2 into matplotlib:main Dec 14, 2022
@timhoffm
Copy link
Member

Thanks @Ali-Msk and congratulations on your first contribution to Matplotlib!

We hope to see you again.

melissawm pushed a commit to melissawm/matplotlib that referenced this pull request Dec 19, 2022
Closes matplotlib#24652


Co-authored-by: Skhaki18 <[email protected]>
Co-authored-by: Krutarth Patel <[email protected]>
Co-authored-by: Oscar Gustafsson <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[Bug]: offsetbox classes have optional arguments that are really not optional
7 participants