-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix minor error in dynamic load function #25256
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
Changes from 2 commits
4b35573
34152ef
480a3de
64ec859
7f7d577
f4704ea
1b1ee48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ | |||||||||||||||||||||||||||||||
import textwrap | ||||||||||||||||||||||||||||||||
import pytest | ||||||||||||||||||||||||||||||||
import numpy as np | ||||||||||||||||||||||||||||||||
import pandas | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import validate_docstrings | ||||||||||||||||||||||||||||||||
validate_one = validate_docstrings.validate_one | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
@@ -1004,6 +1006,30 @@ def test_item_subsection(self, idx, subsection): | |||||||||||||||||||||||||||||||
assert result[idx][3] == subsection | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
class TestDocstringClass(object): | ||||||||||||||||||||||||||||||||
@pytest.mark.parametrize('name_and_expected_obj', | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor stylistic change but you should just be able to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks! I didn't know that pytest would accept that syntax. |
||||||||||||||||||||||||||||||||
[('pandas.isnull', pandas.isnull), | ||||||||||||||||||||||||||||||||
('pandas.DataFrame', pandas.DataFrame), | ||||||||||||||||||||||||||||||||
('pandas.Series.sum', pandas.Series.sum)]) | ||||||||||||||||||||||||||||||||
def test_resolves_class_name(self, name_and_expected_obj): | ||||||||||||||||||||||||||||||||
name, expected_obj = name_and_expected_obj | ||||||||||||||||||||||||||||||||
d = validate_docstrings.Docstring(name) | ||||||||||||||||||||||||||||||||
assert d.obj is expected_obj | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame']) | ||||||||||||||||||||||||||||||||
def test_raises_for_invalid_module_name(self, invalid_name): | ||||||||||||||||||||||||||||||||
# Note that the module names in this test are misspelled. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this ImportError generated by us? or just a generic module name? maybe adding match= here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is raised in the validate_docstrings.py script. That script takes a command-line argument like "pandas.DataFrame.head" or "pandas.isnull" (a string), then dynamically finds the function/method from the string. The script will then validate docstrings for that function only, which is useful for developers working on a particular docstring. pandas/scripts/validate_docstrings.py Lines 258 to 272 in 9c0f6a8
(Note that the snippet above is from master, and contains a bug in the boolean condition. This PR fixes the issue.) I can make the test match the message like so... I don't want to over-specify the message here, so I could also just make sure that the invalid user-supplied is in the exception message. @pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame'])
def test_raises_for_invalid_module_name(self, invalid_name):
msg = 'No module can be imported.*{}'.format(invalid_name)
with pytest.raises(ImportError, match=msg):
validate_docstrings.Docstring(invalid_name) |
||||||||||||||||||||||||||||||||
with pytest.raises(ImportError): | ||||||||||||||||||||||||||||||||
validate_docstrings.Docstring(invalid_name) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@pytest.mark.parametrize('invalid_name', | ||||||||||||||||||||||||||||||||
['pandas.BadClassName', | ||||||||||||||||||||||||||||||||
'pandas.Series.bad_method_name']) | ||||||||||||||||||||||||||||||||
def test_raises_for_invalid_attribute_name(self, invalid_name): | ||||||||||||||||||||||||||||||||
with pytest.raises(AttributeError): | ||||||||||||||||||||||||||||||||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||
validate_docstrings.Docstring(invalid_name) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
class TestMainFunction(object): | ||||||||||||||||||||||||||||||||
def test_exit_status_for_validate_one(self, monkeypatch): | ||||||||||||||||||||||||||||||||
monkeypatch.setattr( | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import pandas as pd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change this.
I originally wrote
import pandas
so that the names and objects on lines 1011-1014 would correspond. But better to be consistent with other usage as you suggest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.