-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Fix encoding of docstring validation for Windows #25466
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25466 +/- ##
==========================================
+ Coverage 91.74% 91.74% +<.01%
==========================================
Files 173 173
Lines 52923 52923
==========================================
+ Hits 48554 48555 +1
+ Misses 4369 4368 -1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25466 +/- ##
==========================================
- Coverage 91.98% 91.98% -0.01%
==========================================
Files 175 175
Lines 52374 52374
==========================================
- Hits 48178 48174 -4
- Misses 4196 4200 +4
Continue to review full report at Codecov.
|
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.
Can you add a test case for the behavior?
running
returns
|
Sure but we need automated tests. You can place one in |
@kpapdac can you merge master to resolve build failure and add a test for this? |
yes, i'm on it! |
ok, i gave it a go, i've never done this before but my best guest is to add to the
For this specific function the test should fail as there is an encoding issue. I doubt that it works though as it passes the test without making any change to |
Hey @kpapdac sorry if I'm misunderstanding, but shouldn't your written test pass if you make no change to the |
scripts/validate_docstrings.py
Outdated
@@ -543,8 +543,8 @@ def validate_pep8(self): | |||
application = flake8.main.application.Application() | |||
application.initialize(["--quiet"]) | |||
|
|||
with tempfile.NamedTemporaryFile(mode='w') as file: | |||
file.write(content) | |||
with tempfile.NamedTemporaryFile(mode='wb') as file: |
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'd prefer opening the NamedTemporaryFile
with encoding='utf-8'
.
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.
Can you address comment from @TomAugspurger here?
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 changed it as @TomAugspurger suggested.
Hi @RjLi13 thank you for having a look at this and apologies for the delay. I think you're right. I changed the test to
so as to fail when the exception is raised. Now, when I change |
@kpapdac Push what you have so we can take a look at the code. |
can you merge master |
@jreback just to clarify I merged and pushed encode_error branch to my master and got a successful built from Travis. Is there anything else i should do to resolve this? Thanks |
@kpapdac your comment above suggests you did but I don't see a test as part of this. Can you double check you included that? |
hi @WillAyd, I added a test for the encoding issue in test_validate_docstrings.py in my master. The name of the test is test_encode_content_write_to_file. |
@kpapdac you'll need to add that test to this PR. Make it locally on your git fetch upstream
git merge upstream/master
git push origin encode_error It should update this PR with your test |
thanks @WillAyd , does it now look ok? |
@@ -6,7 +6,7 @@ | |||
import numpy as np | |||
import pandas as pd | |||
|
|||
import validate_docstrings | |||
from scripts import validate_docstrings |
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 don't see how this is necessary - can you revert this (or let me know what I am missing)
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.
no, my bad i wans't working for me when debugging, i reverted this.
@@ -1052,6 +1052,11 @@ def test_raises_for_invalid_attribute_name(self, invalid_name): | |||
with pytest.raises(AttributeError, match=msg): | |||
validate_docstrings.Docstring(invalid_name) | |||
|
|||
@pytest.mark.parametrize('name', ['pandas.Series.str.isdecimal']) |
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.
If only using one value no need to parametrize - just use this locally in function
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.
In the end I added a second test case to check.
scripts/validate_docstrings.py
Outdated
@@ -543,8 +543,8 @@ def validate_pep8(self): | |||
application = flake8.main.application.Application() | |||
application.initialize(["--quiet"]) | |||
|
|||
with tempfile.NamedTemporaryFile(mode='w') as file: | |||
file.write(content) | |||
with tempfile.NamedTemporaryFile(mode='wb') as file: |
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.
Can you address comment from @TomAugspurger here?
@@ -5,7 +5,6 @@ | |||
import pytest | |||
import numpy as np | |||
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.
Can you also revert this? Probably fails isort or flake8 without it
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.
Minor stuff. So both of the parametrized values were failing on windows before correct? Can't reproduce myself so just want to confirm the choice
@@ -1052,6 +1052,11 @@ def test_raises_for_invalid_attribute_name(self, invalid_name): | |||
with pytest.raises(AttributeError, match=msg): | |||
validate_docstrings.Docstring(invalid_name) | |||
|
|||
@pytest.mark.parametrize('name', ['pandas.Series.str.isdecimal', 'pandas.Series.str.islower']) |
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.
Hmm I don't think our CI is hitting this directory but this would fail linting for being too long. Can you break lines here after the opening left bracket?
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.
Yes, they both fail on windows having characters like '³', '⅕'. I'll break the lines.
@@ -1052,6 +1052,11 @@ def test_raises_for_invalid_attribute_name(self, invalid_name): | |||
with pytest.raises(AttributeError, match=msg): | |||
validate_docstrings.Docstring(invalid_name) | |||
|
|||
@pytest.mark.parametrize('name', ['pandas.Series.str.isdecimal', 'pandas.Series.str.islower']) | |||
def test_encode_content_write_to_file(self, name): | |||
docstr = validate_docstrings.Docstring(name).validate_pep8() # GH25466 |
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.
Move comment one line up (OK to be standalone)
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.
Looks good to me - @datapythonista any chance you can take a look at this one?
@@ -1052,6 +1052,12 @@ def test_raises_for_invalid_attribute_name(self, invalid_name): | |||
with pytest.raises(AttributeError, match=msg): | |||
validate_docstrings.Docstring(invalid_name) | |||
|
|||
@pytest.mark.parametrize('name', [ | |||
'pandas.Series.str.isdecimal', 'pandas.Series.str.islower']) | |||
def test_encode_content_write_to_file(self, name): # GH25466 |
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.
This comment should be on the next line. @kpapdac if you want to fix up otherwise can clean up before merging
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.
yeah, I'm sorry, you said that above but I didn't get it..I'll fix it.
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.
lgtm, added couple of comments, but happy to get this merged as it is too
Thanks @kpapdac
thank you @datapythonista, @WillAyd for all the help |
@kpapdac can you address comments from @datapythonista ? Should be able to get this in thereafter |
Thanks @kpapdac ! |
Thank you! |
In Windows, the
validate_docstrings.py
script fails because an encoding error. It has been fixed here.PR done in the London python sprints meetup.
CC: @datapythonista