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

MAINT: fix incompatible type comparison in numpy.lib.utils.info #17498

Merged

Conversation

stevejoachim
Copy link
Contributor

See ticket #17490

@mattip
Copy link
Member

mattip commented Oct 8, 2020

No test? Under what code path is this hit?

See ticket numpy#17490
Add test to cover the change
Fix if statement to ignore builtin methods that are not printed
@stevejoachim
Copy link
Contributor Author

Hey @mattip thanks for pointing that out. I added a test and actually found that the if statement needed to be more specific. I modified it to ignore builtin methods, since they are not printed anyways. This makes sure that the "Methods:" header won't be printed if there are no methods to document below the header.

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

Generally looks good, a couple suggestions for the test that I would argue make it more readable but that's really just my opinion!

No test? Under what code path is this hit?

AFAICT np.info doesn't appear to be tested anywhere else, so I'm not sure the test is necessary but I think the overall change is an improvement.

numpy/lib/tests/test_utils.py Outdated Show resolved Hide resolved
See ticket numpy#17490
Clean up test style

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Comment on lines 590 to 594

if any(meth[0] != '_' for meth in methods):
print("\n\nMethods:\n", file=output)
for meth in methods:
if meth[0] == '_':
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps better as:

public_methods = [meth for meth in methods if meth[0] != '_']
if public_methods:
    ...

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, that definitely improves readability. If we have the list public_methods available, might as well change this

for meth in methods:
    if meth[0] == '_':
        continue

to this

for meth in public_methods:

since the meth[0] == '_' check is redundant.
Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

That's what I was thinking :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great! I just updated it.

@eric-wieser eric-wieser merged commit aeb2374 into numpy:master Oct 10, 2020
@eric-wieser
Copy link
Member

Thanks for the first contribution @stevejoachim! Given how useless a function np.info is, we were probably overly rigorous on the review here - but I hope it gave you a taste of the type of thing we'd look for in future contributions :)

@stevejoachim
Copy link
Contributor Author

No problem, I appreciated getting the detailed feedback on it. Great way to learn. Thanks!

@stevejoachim stevejoachim deleted the incompatible-type-comparison-patch branch October 10, 2020 16:26
@eric-wieser eric-wieser linked an issue Oct 19, 2020 that may be closed by this pull request
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.

Condition comparing incompatible types in "numpy.lib.utils.info"
4 participants