10000 FIX: Correct variable name from _frame to _frames in PillowWriter class by Anselmoo · Pull Request #29520 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: Correct variable name from _frame to _frames in PillowWriter class #29520

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 3 commits into from
Jan 27, 2025

Conversation

Anselmoo
Copy link
Contributor
@Anselmoo Anselmoo commented Jan 25, 2025

PR summary

Correct the variable name from _frame to _frames in the PillowWriter class to ensure proper functionality.

PR checklist

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 week or so, please leave a new comment below and that should bring it to our attention. 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.

@Anselmoo
Copy link
Contributor Author

@rcomer can you take a look at it later, please?

@@ -526,3 +526,31 @@ def test_movie_writer_invalid_path(anim):
with pytest.raises(FileNotFoundError, match=match_str):
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
writer=animation.FFMpegFileWriter())


def test_exhausted_animation_with_transparency(tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

What exactly is the purpose of the test?

From a quick reading it is

  1. a smoke test to exercise the anim code path for transparency
  2. testing that a saved animation is exhausted.

Can you please describe more precisely what the test wants to ensure? Also it seems (2) is quite unrelated to transparency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal of this test is to actually verify the non-covered section:

if im.getextrema()[3][0] < 255:
            # This frame has transparency, so we'll just add it as is.
            self._frames.append(im)

via savefig_kwargs={"transparent": True}.

I tried just to mock up the class PillowWriter(AbstractMovieWriter):, but it actually raise an error that savefig_kwargs={"transparent": True} is not included. Consequently, I extended a little bit the test. Considering, to leave this part out?

# Verify exhausted warning
    with pytest.warns(UserWarning, match="exhausted"):
        anim._start()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@timhoffm what about this test? Only using the PillowWriter?

def test_animation_with_transparency():
    """Test animation exhaustion with transparency using PillowWriter directly"""
    fig, ax = plt.subplots()
    rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5)
    ax.add_patch(rect)
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

    writer = PillowWriter(fps=30)
    writer.setup(fig, 'unused.gif', dpi=100)
    writer.grab_frame(transparent=True)
    frame = writer._frames[-1]
    # Check that the alpha channel is not 255, so frame has transparency
    assert frame.getextrema()[3][0] < 255
    plt.close(fig)

so the missing part is also captured? thx for feedback

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If former test fits better, I will submit a revert commit

@timhoffm timhoffm added this to the v3.10.1 milestone Jan 27, 2025
@timhoffm timhoffm merged commit 6c5e3f3 into matplotlib:main Jan 27, 2025
39 of 41 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 27, 2025
oscargus added a commit that referenced this pull request Jan 28, 2025
…520-on-v3.10.x

Backport PR #29520 on branch v3.10.x (FIX: Correct variable name from _frame to _frames in PillowWriter class)
@ksunden ksunden mentioned this pull request Mar 3, 2025
5 tasks
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.

[Bug]: 'PillowWriter' object has no attribute '_frame' shoudln't be '_frames'?
3 participants
0