Reformat with YAPF
State: closed

Just as an example (using the default configuration). The same files are adjusted as in https://github.com/pydata/pandas/pull/11951


Labels:
name: Code Style
description: Code style, linting, code_checks

Comments:
Oof, the handling of long strings inside exceptions is pretty ugly, would benefit from manual fixes. Is there any way to get it to automatically fix them?

e.g.

``` python
raise ValueError("this is a really long message"
                 " and continued here")
```

Not sure, I just quickly tried it with the default settings. There are some configuration options: https://github.com/google/yapf#knobs 
And I suppose you could change some of the penalties, but of course that will apply to all opening brackets, and not only to exceptions.

where are we on this @jorisvandenbossche is this 'enough' to make a default formatter?

I think we can use yapf for "fixing" code but I don't think we should use it on any automated basis. The output I see here would need quite a bit of manual fixing (cleaning up long strings in particular)

right. I think we are ok with the `flake8` checks via Travis CI. I just want to document a 'method' of how people should go about conforming to our standard. A configurable tool is prob the best bet here (if it gets most of the way there). I was personally using `autopep8` then manually fixing things. Happy to move to this tool.

I actually think it's good for people to fix their code manually (using flake8 on the command line) as a "learn good style the hard way" -- after a while (at least for me) you stop making style errors as you code. 

I have this in my .emacs which show up red when I have flake8 problems

```
(add-hook 'python-mode-hook
      '(lambda ()
         (define-key python-mode-map "\C-m" 'newline-and-indent)
         (pylint-python-hook)
         (flymake-mode)
         (define-key python-mode-map "\M-n" 'flymake-goto-next-error)
         (define-key python-mode-map "\M-p" 'flymake-goto-prev-error)
))


;; Configure flymake for python
(when (load "flymake" t)
  (defun flymake-pylint-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list "flake8" (list local-file))))

  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pylint-init)))
```

ok with that as well. maybe we need to provide more config for flake8? (its already in `setup.cfg`)

not sure if you can control the backslash breaking (versus parens)

We should put instructions in the developer docs. I looked through flake8 and I didn't see an option to check for usage of backslashes, so we may need to periodically review the codebase for cases that don't get caught during code review

closing in favor of #11951

How long did it take to run yapf on pandas? I remember it being super slow. In fact: https://github.com/google/yapf/issues/96

that is crazy long for that file, very weird! flaking it only takes a second (500 errors though :<)

@hayd It was only a matter of seconds, but only tested on these 3 files.