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

Use the code formatter Black for tsfresh #820

Closed
mendel5 opened this issue Feb 28, 2021 · 7 comments
Closed

Use the code formatter Black for tsfresh #820

mendel5 opened this issue Feb 28, 2021 · 7 comments

Comments

@mendel5
Copy link
Contributor

mendel5 commented Feb 28, 2021

While working with tsfresh I've noticed that in some parts of the code, documentation, etc. single quotes (') are used while in other parts double quotes (") are used.

Examples:

The PEP 8 -- Style Guide for Python Code at https://www.python.org/dev/peps/pep-0008/#string-quotes says this:

In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.

The Comprehensive Knowledge Archive Network (CKAN) has a recommendation at https://docs.ckan.org/en/latest/contributing/python.html#use-single-quotes:

Use single-quotes for string literals, but use double-quotes for strings that are likely to contain single-quote characters as part of the string itself (such as error messages, or any strings containing natural language).

Single-quotes are easier to read and to type, but if a string contains single-quote characters then double-quotes are better than escaping the single-quote characters or wrapping the string in double single-quotes.

The same standards could be applied to docstrings, see PEP 257 -- Docstring Conventions at https://www.python.org/dev/peps/pep-0257/.

CKAN also has a recommendation for docstrings at https://docs.ckan.org/en/latest/contributing/python.html#pep-257-docstring-conventions:

We use '''triple single quotes''' around docstrings, not """triple double quotes""".

I can submit a pull request.

@nils-braun
Copy link
Collaborator

I appreciate your idea on having a common style in the code.

To be fair, using a common quote style is not super usual in python projects (see e.g. numpy) - but we can do this nevertheless - I do not have hard feelings against it.

What I would recommend however is to use as much automation as possible to make it easier for developers to stick with the standard we chose (for example, I am working with a German keyboard where the " is easier to reach than the ' - at least on my keyboard). So I would propose to maybe go with a tool like "black" (as was suggested e.g. in #607) and add it to both the CI pipeline as well as the contribution guidelines.
(black, by the way prefers double quotes).

Just out of curiosity: I worked with several open and close source python applications so far, but I have barely never seen single quotes used for docstrings - also because PEP-257 uses double quotes. Do you know a reason why single triple quotes were chosen?

@MaxBenChrist
Copy link
Collaborator

Maybe we could add pylint with the following add-on https://github.com/edaniszewski/pylint-quotes to check this in the CI pipeline

@mendel5
Copy link
Contributor Author

mendel5 commented Jun 2, 2021

Related to #858

@nils-braun I finally found the time to start working on this, see #858

@mendel5
Copy link
Contributor Author

mendel5 commented Jul 1, 2021

New pull request with the python package "black" applied to the tsfresh repository:

@mendel5 mendel5 changed the title Adopt CKAN Python coding standards: Use single quotes instead of double quotes Use the code formatter Black for tsfresh Jul 13, 2021
@mendel5
Copy link
Contributor Author

mendel5 commented Jul 13, 2021

I have renamed this issue to better reflect the changes that were made.

Old name:

Adopt CKAN Python coding standards: Use single quotes instead of double quotes

New name:

Use the code formatter Black for tsfresh

https://github.com/psf/black

@mendel5 mendel5 closed this as completed Jul 13, 2021
@nils-braun
Copy link
Collaborator

Well done and well documented!

@mendel5
Copy link
Contributor Author

mendel5 commented Jul 13, 2021

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants