Pandas Doc update – PEP8

Pandas is a data analysis library for Python. It has become the most powerful open source data analysis tool since there are many features which enable the user to analyse the data easily. Since Pandas is written in Python, they wanted to update all of their codes, and documentations based on PEP 8, the official style guide for Python code. One of the issues were updating the Python code in Pandas documentation with the file format called reStructuredText.

Here is the issue. This documentation was not following the PEP-8 standard, so that it needed to be updated. Thankfully, the person who filed this issue provided an instruction on how to find the errors using the code styling tool for PEP-8 standard, called flake8-rst. Since I did not have this tool installed, I installed this tool using ‘conda’, package management system. I run this command to install flake8-rst :

conda install -c conda-forge flake8-rst=0.5.0

When I run this tool, I got these errors below :

$ flake8-rst doc/source/basics.rst 
doc/source/basics.rst:309:10: E225 missing whitespace around operator
doc/source/basics.rst:6:4: E902 TokenError: EOF in multi-line statement
doc/source/basics.rst:152:28: E203 whitespace before ':'
doc/source/basics.rst:152:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:153:28: E203 whitespace before ':'
doc/source/basics.rst:153:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:154:30: E203 whitespace before ':'
doc/source/basics.rst:154:83: E501 line too long (83 > 79 characters)
doc/source/basics.rst:175:46: E231 missing whitespace after ','
doc/source/basics.rst:175:51: E231 missing whitespace after ','
doc/source/basics.rst:175:54: E231 missing whitespace after ','
doc/source/basics.rst:175:59: E231 missing whitespace after ','
doc/source/basics.rst:175:62: E231 missing whitespace after ','
doc/source/basics.rst:175:67: E231 missing whitespace after ','
doc/source/basics.rst:175:70: E231 missing whitespace after ','
doc/source/basics.rst:176:57: E231 missing whitespace after ','
doc/source/basics.rst:339:6: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:339:15: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:340:7: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:340:16: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:355:7: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:355:21: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:362:29: E231 missing whitespace after ':'
doc/source/basics.rst:363:29: E231 missing whitespace after ':'
doc/source/basics.rst:363:59: E231 missing whitespace after ','
doc/source/basics.rst:363:61: E231 missing whitespace after ','
doc/source/basics.rst:426:27: E203 whitespace before ':'
doc/source/basics.rst:427:27: E203 whitespace before ':'
doc/source/basics.rst:428:27: E203 whitespace before ':'
doc/source/basics.rst:429:27: E203 whitespace before ':'
doc/source/basics.rst:446:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:549:17: E221 multiple spaces before operator
doc/source/basics.rst:566:84: E501 line too long (81 > 79 characters)
doc/source/basics.rst:622:40: E231 missing whitespace after ','
doc/source/basics.rst:622:57: E231 missing whitespace after ','
doc/source/basics.rst:622:61: E231 missing whitespace after ','
doc/source/basics.rst:751:4: E402 module level import not at top of file
doc/source/basics.rst:756:19: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:756:21: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:760:4: E124 closing bracket does not match visual indentation
doc/source/basics.rst:883:83: E501 line too long (86 > 79 characters)
doc/source/basics.rst:927:7: E111 indentation is not a multiple of four
doc/source/basics.rst:980:4: E402 module level import not at top of file
doc/source/basics.rst:1041:39: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1048:41: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1059:49: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1067:50: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1087:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:1099:24: E203 whitespace before ':'
doc/source/basics.rst:1099:38: E203 whitespace before ':'
doc/source/basics.rst:1115:4: E402 module level import not at top of file
doc/source/basics.rst:1124:36: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1152:15: E126 continuation line over-indented for hanging indent
doc/source/basics.rst:1152:27: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1152:37: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1162:4: E731 do not assign a lambda expression, use a def
doc/source/basics.rst:1162:23: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1162:34: E226 missing whitespace around arithmetic operator
doc/source/basics.rst:1164:32: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:1164:34: E251 unexpected spaces around keyword / parameter equals
doc/source/basics.rst:1164:43: E231 missing whitespace after ','
doc/source/basics.rst:1166:16: E231 missing whitespace after ','
doc/source/basics.rst:1166:18: E231 missing whitespace after ','
doc/source/basics.rst:1172:28: E201 whitespace after '['
doc/source/basics.rst:1172:47: E231 missing whitespace after ','
doc/source/basics.rst:1172:49: E231 missing whitespace after ','
doc/source/basics.rst:1173:28: E128 continuation line under-indented for visual indent
doc/source/basics.rst:1173:54: E202 whitespace before ']'
doc/source/basics.rst:1175:16: E231 missing whitespace after ','
doc/source/basics.rst:1175:18: E231 missing whitespace after ','
doc/source/basics.rst:1505:38: E203 whitespace before ':'
doc/source/basics.rst:1505:67: E203 whitespace before ':'
doc/source/basics.rst:1628:34: E231 missing whitespace after ','
doc/source/basics.rst:1679:14: E225 missing whitespace around operator
doc/source/basics.rst:1775:28: E203 whitespace before ':'
doc/source/basics.rst:1775:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:1776:28: E203 whitespace before ':'
doc/source/basics.rst:1776:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:1777:30: E203 whitespace before ':'
doc/source/basics.rst:1777:83: E501 line too long (83 > 79 characters)
doc/source/basics.rst:1803:29: E231 missing whitespace after ':'
doc/source/basics.rst:1803:32: E231 missing whitespace after ','
doc/source/basics.rst:1803:34: E231 missing whitespace after ','
doc/source/basics.rst:1803:36: E231 missing whitespace after ','
doc/source/basics.rst:1803:39: E231 missing whitespace after ','
doc/source/basics.rst:1803:45: E231 missing whitespace after ':'
doc/source/basics.rst:1803:48: E231 missing whitespace after ','
doc/source/basics.rst:1803:50: E231 missing whitespace after ','
doc/source/basics.rst:1803:52: E231 missing whitespace after ','
doc/source/basics.rst:1803:55: E231 missing whitespace after ','
doc/source/basics.rst:1803:63: E231 missing whitespace after ':'
doc/source/basics.rst:1803:66: E231 missing whitespace after ','
doc/source/basics.rst:1803:68: E231 missing whitespace after ','
doc/source/basics.rst:1803:70: E231 missing whitespace after ','
doc/source/basics.rst:1810:54: E231 missing whitespace after ','
doc/source/basics.rst:1913:49: E231 missing whitespace after ','
doc/source/basics.rst:1913:56: E231 missing whitespace after ','
doc/source/basics.rst:1913:61: E231 missing whitespace after ','
doc/source/basics.rst:1913:68: E231 missing whitespace after ','
doc/source/basics.rst:1913:73: E231 missing whitespace after ','
doc/source/basics.rst:1913:83: E501 line too long (80 > 79 characters)
doc/source/basics.rst:1914:27: E231 missing whitespace after ','
doc/source/basics.rst:1986:5: E999 SyntaxError: invalid syntax
doc/source/basics.rst:2010:83: E501 line too long (85 > 79 characters)
doc/source/basics.rst:2124:85: E501 line too long (83 > 79 characters)
doc/source/basics.rst:2212:84: E501 line too long (81 > 79 characters)

These errors occurred mostly because of spacing issues, or character limits per line. Most of the issues were fixed smoothly, but I could not fix these errors :

doc/source/basics.rst:310:10: E225 missing whitespace around operator
doc/source/basics.rst:6:4: E902 TokenError: EOF in multi-line statement
doc/source/basics.rst:754:4: E402 module level import not at top of file
doc/source/basics.rst:984:4: E402 module level import not at top of file
doc/source/basics.rst:1120:4: E402 module level import not at top of file
doc/source/basics.rst:1992:5: E999 SyntaxError: invalid syntax

I posted Pull Request with these errors for clarification, and I got the feedback for extra changes. At the end, I got these errors, and was told that these errors should not be reported by flake8-rst.

doc/source/basics.rst:753:4: E402 module level import not at top of file
doc/source/basics.rst:983:4: E402 module level import not at top of file
doc/source/basics.rst:1119:4: E402 module level import not at top of file
doc/source/basics.rst:2128:6: E402 module level import not at top of file
doc/source/basics.rst:2158:6: E402 module level import not at top of file
doc/source/basics.rst:2178:5: E402 module level import not at top of file
doc/source/basics.rst:2193:5: E402 module level import not at top of file
doc/source/basics.rst:2219:5: E402 module level import not at top of file

The person who handle this approved my Pull Request, and it was great until I committed new updates. I was trying to update other issues, and new changes were pushed to my ‘master’ branch of forked repository. It was totally my mistake that I forgot to make the new branch for this issue. I tried to revert the changes, create new branch on local, and even move the HEAD pointer to the previous commits, but it was not working properly. I explained this situation, and they told me that they can manage the commits, but suggested to create new branch for each issue. Finally, my PR was merged to Pandas master branch.

From this Pull Request, I learned a lot about Python coding style, PEP-8 standard, as well as the rst documentation. Also, it was very interesting that coding style tools can help developers to fix the errors against the coding standards. I know that there are many coding style tools for JavaScript, such as ESLint, or Prettier, but this tool, flake8, will save lots of time for fixing the potential errors since Python uses spaces, instead of semi-colon.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close