From 8dba111fafb253e59f95180aad70c0306245c669 Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:18:12 +0000 Subject: [PATCH 1/6] FIX: [Bug]: ValueError: The truth value... when an ndarray is passed to the color kwarg of axes3d.scatter --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index c519bc656533..0c18bce8ebd3 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2672,7 +2672,7 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, xs, ys, zs, s, c, color = cbook.delete_masked_points( xs, ys, zs, s, c, kwargs.get('color', None) ) - if kwargs.get('color', None): + if kwargs.get("color") is not None: kwargs['color'] = color # For xs and ys, 2D scatter() will do the copying. From fa5fb05ed7b069e53be47afb4e9d775b5ecb0ba5 Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:55:24 +0000 Subject: [PATCH 2/6] added smoke test to ensure no value error is thrown --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index 75f0e2261907..d71fc42bd215 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2302,3 +2302,12 @@ def test_Poly3DCollection_init_value_error(): 'or both for shade to work.'): poly = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float) c = art3d.Poly3DCollection([poly], shade=True) + +def test_ndarray_color_kwargs_value_error(): + # smoke test to ensure that ndarray can be passed to color in kwargs for a 3d projection plot + try: + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1])) + except ValueError: + pytest.fail("A ValueError was raised when it shouldn't have.") From e8b4779fabc0103905f08a9bae470863b128f161 Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:57:03 +0000 Subject: [PATCH 3/6] fixed smoke test to use fig canvas draw rather than plt show --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index d71fc42bd215..cf0f9aea358f 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2309,5 +2309,6 @@ def test_ndarray_color_kwargs_value_error(): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1])) + fig.canvas.draw() except ValueError: pytest.fail("A ValueError was raised when it shouldn't have.") From 20ae439d72341ad9758ee4ff5ae49070411b8a0c Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Wed, 20 Sep 2023 00:01:38 +0000 Subject: [PATCH 4/6] added an extra line and reduced line length to comply with flake8 --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index cf0f9aea358f..2c63b7ab16ad 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2303,8 +2303,10 @@ def test_Poly3DCollection_init_value_error(): poly = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float) c = art3d.Poly3DCollection([poly], shade=True) + def test_ndarray_color_kwargs_value_error(): - # smoke test to ensure that ndarray can be passed to color in kwargs for a 3d projection plot + # smoke test + # ensures ndarray can be passed to color in kwargs for 3d projection plot try: fig = plt.figure() ax = fig.add_subplot(111, projection='3d') From 77634cc4cc8c290cd8bef6b3b22632edb9d7ab12 Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Wed, 20 Sep 2023 00:03:49 +0000 Subject: [PATCH 5/6] removed trailing whitespace --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index 2c63b7ab16ad..d5bd0f3ba9bb 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2305,7 +2305,7 @@ def test_Poly3DCollection_init_value_error(): def test_ndarray_color_kwargs_value_error(): - # smoke test + # smoke test # ensures ndarray can be passed to color in kwargs for 3d projection plot try: fig = plt.figure() From 2d4ac9f1efff0bfd1e8929e6c89fa56265d2f3f3 Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Tue, 19 Sep 2023 17:51:21 -0700 Subject: [PATCH 6/6] Update lib/mpl_toolkits/mplot3d/tests/test_axes3d.py Co-authored-by: Kyle Sunden --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index d5bd0f3ba9bb..f3666fffc418 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2307,10 +2307,7 @@ def test_Poly3DCollection_init_value_error(): def test_ndarray_color_kwargs_value_error(): # smoke test # ensures ndarray can be passed to color in kwargs for 3d projection plot - try: - fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') - ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1])) - fig.canvas.draw() - except ValueError: - pytest.fail("A ValueError was raised when it shouldn't have.") + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1])) + fig.canvas.draw()