From 8e455c7e6eba50542a0b62fbd4087fa0ec65ff0b Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Wed, 24 Mar 2021 20:13:21 +0530 Subject: [PATCH 01/11] Fix test_utils.py warning --- fury/tests/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index 1d54000b6..d58a68b5e 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -130,9 +130,9 @@ def trilinear_interp_numpy(input_array, indices): y_indices = indices[:, 1] z_indices = indices[:, 2] - x0 = x_indices.astype(np.integer) - y0 = y_indices.astype(np.integer) - z0 = z_indices.astype(np.integer) + x0 = x_indices.astype(np.int64) + y0 = y_indices.astype(np.int64) + z0 = z_indices.astype(np.int64) x1 = x0 + 1 y1 = y0 + 1 z1 = z0 + 1 From 73453ee3b1d1985e858fc387f2c6646828f8ea66 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Thu, 25 Mar 2021 06:42:23 +0530 Subject: [PATCH 02/11] This should fix (#355): --- docs/source/ext/github_tools.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/source/ext/github_tools.py b/docs/source/ext/github_tools.py index 68ab43cdf..1a97a8dcf 100644 --- a/docs/source/ext/github_tools.py +++ b/docs/source/ext/github_tools.py @@ -42,6 +42,10 @@ def fetch_url(url): + # This was pointed out as a Security issue in bandit. + # please look at issue #355, + # we fixed it, but the bandit warning might remain, + # need to suppress it manually ¯\_(ツ)_/¯. req = Request(url) if GH_TOKEN: req.add_header('Authorization', 'token {0}'.format(GH_TOKEN)) @@ -50,7 +54,8 @@ def fetch_url(url): # url = Request(url, # headers={'Accept': 'application/vnd.github.v3+json', # 'User-agent': 'Defined'}) - f = urlopen(req) + if url.lower().startswith('http'): + f = urlopen(req) except Exception as e: print(e) print("return Empty data", file=sys.stderr) From c2706b3454c101367cc37c5d71b3abcb76cc4929 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 11:43:49 +0530 Subject: [PATCH 03/11] test_actors.py: Fix 1 unecessary warning --- fury/tests/test_actors.py | 2 +- fury/window.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 46fe67142..479b34f9f 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -950,7 +950,7 @@ def test_cones_vertices_faces(interactive=False): if interactive: window.show(scene, order_transparent=True) arr = window.snapshot(scene) - report = window.analyze_snapshot(arr, colors=[colors]) + report = window.analyze_snapshot(arr, colors=colors) npt.assert_equal(report.objects, 3) scene.clear() diff --git a/fury/window.py b/fury/window.py index 4eeae0635..f6915ca72 100644 --- a/fury/window.py +++ b/fury/window.py @@ -1082,7 +1082,8 @@ def __str__(self): flags = [False] * len(colors) for (i, col) in enumerate(colors): # find if the current color exist in the array - flags[i] = np.any(np.any(np.all(im[..., :3] == col[:3], axis=-1))) + flags[i] = np.any(np.any(np.all(np.equal(im[..., :3], col[:3]), + axis=-1))) report.colors_found = flags From ed96c1753699c5f0a69fe70a05d6c0af58c375d0 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 15:43:33 +0530 Subject: [PATCH 04/11] Basic Convert.py testing --- fury/tests/test_convert.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 fury/tests/test_convert.py diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py new file mode 100644 index 000000000..deb5359fa --- /dev/null +++ b/fury/tests/test_convert.py @@ -0,0 +1,30 @@ +import os + +import numpy.testing as npt +from fury import convert +from tempfile import TemporaryDirectory +from fury.io import load_image +import matplotlib.pyplot as plt + + +def test_convert(): + names = ['group_a', 'group_b', 'group_c'] + values = [1, 10, 100] + + fig = plt.figure(figsize=(9, 3)) + # plt.subplot(131) + # plt.bar(names, values) + # plt.subplot(132) + # plt.scatter(names, values) + # plt.subplot(133) + # plt.plot(names, values) + # plt.suptitle('Categorical Plotting') + + arr2 = convert.matplotlib_figure_to_numpy(fig, transparent=True) + + with TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'tmp.png') + dpi = 100 + fig.savefig(fname, dpi=dpi, transparent=True) + arr1 = load_image(fname) + npt.assert_array_equal(arr1, arr2) From a92ddf99fd4699ea19c196284aff2cacc820ac18 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 15:44:06 +0530 Subject: [PATCH 05/11] pep8 fix --- fury/tests/test_convert.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index deb5359fa..05fa3dd9c 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -19,7 +19,6 @@ def test_convert(): # plt.subplot(133) # plt.plot(names, values) # plt.suptitle('Categorical Plotting') - arr2 = convert.matplotlib_figure_to_numpy(fig, transparent=True) with TemporaryDirectory() as tmpdir: From ad8120b79777b7036dbc6b483b7fcbfbb9249041 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 20:06:42 +0530 Subject: [PATCH 06/11] CI: fix matplot lib is an Optional Module --- fury/tests/test_convert.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index 05fa3dd9c..cb1f5a674 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -4,9 +4,12 @@ from fury import convert from tempfile import TemporaryDirectory from fury.io import load_image -import matplotlib.pyplot as plt +# Optional packages +from fury.optpkg import optional_package +matplotlib, have_matplotlib, _ = optional_package('matplotlib') +@pytest.mark.skipif(not have_matplotlib, reason="Requires MatplotLib") def test_convert(): names = ['group_a', 'group_b', 'group_c'] values = [1, 10, 100] From 00c5c44396a856a99f157e9d323007019b2eadda Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 20:12:32 +0530 Subject: [PATCH 07/11] forgot import in test_convert.py -_- Effects of sleep deprivation --- fury/tests/test_convert.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index cb1f5a674..c9e127cd3 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -1,5 +1,5 @@ import os - +import pytest import numpy.testing as npt from fury import convert from tempfile import TemporaryDirectory From 5905d82a04840d718eaf4aa6c02916acd7017f6d Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Fri, 26 Mar 2021 20:23:21 +0530 Subject: [PATCH 08/11] CI fix: proper imports --- fury/tests/test_convert.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index c9e127cd3..7e3616943 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -1,13 +1,16 @@ import os import pytest import numpy.testing as npt -from fury import convert from tempfile import TemporaryDirectory from fury.io import load_image # Optional packages from fury.optpkg import optional_package matplotlib, have_matplotlib, _ = optional_package('matplotlib') +if have_matplotlib: + import matplotlib.pyplot as plt + from fury.convert import matplotlib_figure_to_numpy + @pytest.mark.skipif(not have_matplotlib, reason="Requires MatplotLib") def test_convert(): @@ -22,7 +25,7 @@ def test_convert(): # plt.subplot(133) # plt.plot(names, values) # plt.suptitle('Categorical Plotting') - arr2 = convert.matplotlib_figure_to_numpy(fig, transparent=True) + arr2 = matplotlib_figure_to_numpy(fig, transparent=True) with TemporaryDirectory() as tmpdir: fname = os.path.join(tmpdir, 'tmp.png') From 185200e99228d746ca42f9ac10f403056546240c Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Mon, 29 Mar 2021 21:47:14 +0530 Subject: [PATCH 09/11] Made the suggested Changes in review. --- docs/source/ext/github_tools.py | 14 ++++++++------ fury/tests/test_convert.py | 4 ++-- fury/tests/test_utils.py | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/source/ext/github_tools.py b/docs/source/ext/github_tools.py index 1a97a8dcf..5966e3ade 100644 --- a/docs/source/ext/github_tools.py +++ b/docs/source/ext/github_tools.py @@ -42,10 +42,10 @@ def fetch_url(url): - # This was pointed out as a Security issue in bandit. - # please look at issue #355, - # we fixed it, but the bandit warning might remain, - # need to suppress it manually ¯\_(ツ)_/¯. + '''This was pointed out as a Security issue in bandit. + please look at issue #355, + we fixed it, but the bandit warning might remain, + need to suppress it manually (just ignore it)''' req = Request(url) if GH_TOKEN: req.add_header('Authorization', 'token {0}'.format(GH_TOKEN)) @@ -54,8 +54,10 @@ def fetch_url(url): # url = Request(url, # headers={'Accept': 'application/vnd.github.v3+json', # 'User-agent': 'Defined'}) - if url.lower().startswith('http'): - f = urlopen(req) + if not url.lower().startswith('http'): + msg = "Please make sure you use http/https connection" + raise ValueError(msg) + f = urlopen(req) except Exception as e: print(e) print("return Empty data", file=sys.stderr) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index 7e3616943..568c412ad 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -25,11 +25,11 @@ def test_convert(): # plt.subplot(133) # plt.plot(names, values) # plt.suptitle('Categorical Plotting') - arr2 = matplotlib_figure_to_numpy(fig, transparent=True) + arr2 = matplotlib_figure_to_numpy(fig, transparent=False) with TemporaryDirectory() as tmpdir: fname = os.path.join(tmpdir, 'tmp.png') dpi = 100 - fig.savefig(fname, dpi=dpi, transparent=True) + fig.savefig(fname, dpi=dpi, transparent=False) arr1 = load_image(fname) npt.assert_array_equal(arr1, arr2) diff --git a/fury/tests/test_utils.py b/fury/tests/test_utils.py index d58a68b5e..963d83e27 100644 --- a/fury/tests/test_utils.py +++ b/fury/tests/test_utils.py @@ -130,9 +130,9 @@ def trilinear_interp_numpy(input_array, indices): y_indices = indices[:, 1] z_indices = indices[:, 2] - x0 = x_indices.astype(np.int64) - y0 = y_indices.astype(np.int64) - z0 = z_indices.astype(np.int64) + x0 = x_indices.astype(int) + y0 = y_indices.astype(int) + z0 = z_indices.astype(int) x1 = x0 + 1 y1 = y0 + 1 z1 = z0 + 1 From d8c61736d7cb557074b4127f853b2888d0860a6f Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Tue, 30 Mar 2021 20:43:14 +0530 Subject: [PATCH 10/11] Revised changes: --- docs/source/ext/github_tools.py | 5 +++-- fury/tests/test_convert.py | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/source/ext/github_tools.py b/docs/source/ext/github_tools.py index 5966e3ade..242613b31 100644 --- a/docs/source/ext/github_tools.py +++ b/docs/source/ext/github_tools.py @@ -42,10 +42,11 @@ def fetch_url(url): - '''This was pointed out as a Security issue in bandit. + """This was pointed out as a Security issue in bandit. please look at issue #355, we fixed it, but the bandit warning might remain, - need to suppress it manually (just ignore it)''' + need to suppress it manually (just ignore it) + """ req = Request(url) if GH_TOKEN: req.add_header('Authorization', 'token {0}'.format(GH_TOKEN)) diff --git a/fury/tests/test_convert.py b/fury/tests/test_convert.py index 568c412ad..3164ebf8e 100644 --- a/fury/tests/test_convert.py +++ b/fury/tests/test_convert.py @@ -18,18 +18,20 @@ def test_convert(): values = [1, 10, 100] fig = plt.figure(figsize=(9, 3)) - # plt.subplot(131) - # plt.bar(names, values) - # plt.subplot(132) - # plt.scatter(names, values) - # plt.subplot(133) - # plt.plot(names, values) - # plt.suptitle('Categorical Plotting') - arr2 = matplotlib_figure_to_numpy(fig, transparent=False) + plt.subplot(131) + plt.bar(names, values) + plt.subplot(132) + plt.scatter(names, values) + plt.subplot(133) + plt.plot(names, values) + plt.suptitle('Categorical Plotting') + arr2 = matplotlib_figure_to_numpy(fig, transparent=False, + flip_up_down=False) with TemporaryDirectory() as tmpdir: fname = os.path.join(tmpdir, 'tmp.png') dpi = 100 - fig.savefig(fname, dpi=dpi, transparent=False) + fig.savefig(fname, transparent=False, bbox_inches='tight', + pad_inches=0) arr1 = load_image(fname) npt.assert_array_equal(arr1, arr2) From f87206e029b4e31c98e2d6171bada7939ea04966 Mon Sep 17 00:00:00 2001 From: Amit Chaudhari Date: Tue, 30 Mar 2021 22:13:24 +0530 Subject: [PATCH 11/11] Revised Changes --- docs/source/ext/github_tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/ext/github_tools.py b/docs/source/ext/github_tools.py index 242613b31..3c379467d 100644 --- a/docs/source/ext/github_tools.py +++ b/docs/source/ext/github_tools.py @@ -42,7 +42,10 @@ def fetch_url(url): - """This was pointed out as a Security issue in bandit. + """ + Notes + ----- + This was pointed out as a Security issue in bandit. please look at issue #355, we fixed it, but the bandit warning might remain, need to suppress it manually (just ignore it)