Skip to content
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

Resolve warnings #317 & and Fix Issue: #355 #399

Merged
merged 11 commits into from
Mar 31, 2021
Merged

Resolve warnings #317 & and Fix Issue: #355 #399

merged 11 commits into from
Mar 31, 2021

Conversation

amit-chaudhari1
Copy link
Contributor

This commit will hopefully close issues #317 and #355.

I did not create tests for layout.py since it looks like a helper in actors.py.
I could say the same about convert.py but even then, I tried creating basic tests.
If these files grow in future, they might need their own tests.

As for #355, it's a really simple check just before we fetch the url.

Thank you for your time!
I'd appreciate any feedback...

@amit-chaudhari1
Copy link
Contributor Author

These Checks seem to be failing cause I assumed matplotlib is installed. It's not.
I'll push another commit that solves this, soon.

@codecov
Copy link

codecov bot commented Mar 26, 2021

Codecov Report

Merging #399 (f87206e) into master (068f2e9) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #399      +/-   ##
==========================================
+ Coverage   89.00%   89.04%   +0.04%     
==========================================
  Files          23       23              
  Lines        5376     5388      +12     
  Branches      695      695              
==========================================
+ Hits         4785     4798      +13     
  Misses        411      411              
+ Partials      180      179       -1     
Impacted Files Coverage Δ
fury/window.py 78.75% <100.00%> (ø)
fury/actor.py 92.95% <0.00%> (+0.04%) ⬆️
fury/primitive.py 91.78% <0.00%> (+0.23%) ⬆️
fury/convert.py 80.00% <0.00%> (+6.66%) ⬆️

@amit-chaudhari1
Copy link
Contributor Author

Uwa!!! help me please,
The failing CI checks are not giving me any good information...

CI is important, but in my case it takes me more time to notice and rectify my mistakes that CI catches, than it takes me to do the maintenance work... ;-;


even on the Previous PR, I could not pass all the CI checks...

@skoudoro skoudoro added this to the v0.8.0 milestone Mar 29, 2021
Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @amitchaudhari9121,

Thank you for fixing these 2 issues! overall, it looks good. It just needs some reshaping.

Thank you

Comment on lines 133 to 135
x0 = x_indices.astype(np.int64)
y0 = y_indices.astype(np.int64)
z0 = z_indices.astype(np.int64)
Copy link
Contributor

Choose a reason for hiding this comment

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

int instead of np.int64. it does not need to force 64bit

Comment on lines 30 to 35
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

I've (kindof) picked it up from the code you wrote 😅
This just tests the exact way its written in test_actors.py

But it's not redundant code. if something breaks in future. (or we add more conversion definitions) this will be useful...

Comment on lines 21 to 27
# 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')
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it commented? your figure seems empty

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 test failed for some reason when I added these args,

I think I could just test an empty figure, and confirm it works.
will that be the case?

I'm not sure...

I don't understand enough about matplotlib, so I can't reliably say why it fails when I uncomment it...
I'll keep researching & hopefully find a fix.

Any suggestions? any idea why this might be failing? any guess is appreciated...

Copy link
Contributor

Choose a reason for hiding this comment

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

See below the test updated. I admit that it was tricky., you had to update the matplotlib_figure_to_numpy option and the fig.savefig options to make sure that both images have the same size and orientation.

    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,
                                      flip_up_down=False)

    with TemporaryDirectory() as tmpdir:
        fname = os.path.join(tmpdir, 'tmp.png')
        fig.savefig(fname, transparent=False, bbox_inches='tight',
                    pad_inches=0)
        arr1 = load_image(fname)
        npt.assert_array_equal(arr1, arr2)

# plt.subplot(133)
# plt.plot(names, values)
# plt.suptitle('Categorical Plotting')
arr2 = matplotlib_figure_to_numpy(fig, transparent=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

for more control in your test, use transparent=False

Comment on lines 45 to 48
# 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 ¯\_(ツ)_/¯.
Copy link
Contributor

Choose a reason for hiding this comment

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

to convert to a complete docstring with a NOTE section

Comment on lines 57 to 58
if url.lower().startswith('http'):
f = urlopen(req)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if it does not start with http? here a proposition:

if not url.lower().startswith('http'):
    msg = "custom message"
    raise ValueError(msg)
f= urlopen(req)

The ValueError will need to be tested with npt.assert_raises

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice!
It didn't even cross my mind !!!
I will change in next commit, thank you for this.

@skoudoro
Copy link
Contributor

concerning the tests, no worries. We will need to make some of them more robust

Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @amitchaudhari9121,

See below for some suggestions to update your test. After those update, I think your PR will be ready to go.
Thanks!

Comment on lines 45 to 48
'''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)'''
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring is incomplete. Please, use double-quotes and follow the standard of our docstring. As an example, you can look here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do I stop making these types of mistakes?

It might be annoying for you, I'm sorry for the inconvinience.

My VScode does not pick them up ( I've been using pycodestyle as a linter)

Copy link
Contributor

Choose a reason for hiding this comment

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

You did not address my comment above. Please, look at the example cited above and complete the docstring.
As suggested, the text should be in a NOTE

Comment on lines 21 to 27
# 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')
Copy link
Contributor

Choose a reason for hiding this comment

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

See below the test updated. I admit that it was tricky., you had to update the matplotlib_figure_to_numpy option and the fig.savefig options to make sure that both images have the same size and orientation.

    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,
                                      flip_up_down=False)

    with TemporaryDirectory() as tmpdir:
        fname = os.path.join(tmpdir, 'tmp.png')
        fig.savefig(fname, transparent=False, bbox_inches='tight',
                    pad_inches=0)
        arr1 = load_image(fname)
        npt.assert_array_equal(arr1, arr2)

@skoudoro
Copy link
Contributor

Thank you for working on this @amitchaudhari9121. merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants