Skip to content

Fix IndexError when using scatter3d and depthshade=False - #18156

Merged
dstansby merged 5 commits into
matplotlib:masterfrom
neil-ptr:bug-fix-issue-18037
Aug 3, 2020
Merged

dstansby merged 5 commits into
matplotlib:masterfrom
neil-ptr:bug-fix-issue-18037

Conversation

@neil-ptr

@neil-ptr neil-ptr commented Aug 2, 2020 •

Copy link
Copy Markdown
Contributor

PR Summary

Minor bug fix for issue #18037 that resulted in an IndexError when plotting more than 2 points on 3d scatter plot with depthshade=False

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant

Comment thread lib/mpl_toolkits/tests/test_mplot3d.py Outdated
@mpl3d_image_comparison(['scatter3d_depthshade_false.png'])
def test_scatter3d_depthshade_false():
"""
Test that 3d scatter plot works with depthshade=False (issue #18037)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We try to be stingy with our image tests. If this is just a test to see if depthshade=False works then maybe if doesn't need the image comparison (faster, takes less disk space etc)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll work on changing this. Thanks for the feedback!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... you are allowed to claim it does need an image test, but no need to include one if its not necessary...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this might need an image test. I can't think of another way to generate a baseline figure without using the method being tested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can always generate a figure, but not check the image output (just don't add the mpl3d_image_comparison decorator). Since the original bug resulted in a traceback, that would be enough to test that the bug is fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Neilzon You don't need to compare figures either. You can just do

     x = y = z = np.arange(16)
     ax_test = fig_test.add_subplot(projection='3d')
     ax_test.scatter(x, y, z, depthshade=False)

and the figure will get made. If the code you are testing throws an error, the test will fail. If not, then it will pass. We call this a "smoketest" because it just checks that the code runs, and nothing else. But bear in mind this test would fail on master right now, so its still a worthwhile (and quick!) test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh ok, I understand now. Thank you for the guidance!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can't seem to get my code to fail now with this test

@jklymak

jklymak commented Aug 2, 2020

Copy link
Copy Markdown
Member

This looks fine to me. And thanks for adding a test, though see the note above!

@dstansby dstansby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! The fix looks good to me. For the test, please could you remove the test image, and I don't think a figure comparison needs to be done. It is fine just to check that the code runs without producing an error, so the check_figures_equal can be removed, and you only have to create one figure/axes to check the code works.

@dstansby dstansby added this to the v3.3.1 milestone Aug 3, 2020
@jklymak
jklymak requested a review from dstansby August 3, 2020 16:56
@dstansby

dstansby commented Aug 3, 2020

Copy link
Copy Markdown
Member

Squash merging to make sure the image doesn't get committed

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.

4 participants