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

Isort contributing guide #23364

Merged
merged 4 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,54 @@ Alternatively, you can install the ``grep`` and ``xargs`` commands via the
`MinGW <http://www.mingw.org/>`__ toolchain, and it will allow you to run the
commands above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a ref tag here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - done

.. _contributing.import-formatting:

Import Formatting
~~~~~~~~~~~~~~~~~
*pandas* uses `isort <https://pypi.org/project/isort/>`__ to standardise import
formatting across the codebase.

A guide to import layout as per pep8 can be found `here <https://www.python.org/dev/peps/pep-0008/#imports/>`__.

A summary of our current import sections ( in order ):

* Future
* Python Standard Library
* Third Party
* ``pandas._libs``, ``pandas.compat``, ``pandas.util._*``, ``pandas.errors`` (largely not dependent on ``pandas.core``)
* ``pandas.core.dtypes`` (largely not dependent on the rest of ``pandas.core``)
* Rest of ``pandas.core.*``
* Non-core ``pandas.io``, ``pandas.plotting``, ``pandas.tseries``
* Local application/library specific imports

Imports are alphabetically sorted within these sections.


As part of :ref:`Continuous Integration <contributing.ci>` checks we run::

isort --recursive --check-only pandas

to check that imports are correctly formatted as per the `setup.cfg`.

If you see output like the below in :ref:`Continuous Integration <contributing.ci>` checks:

.. code-block:: shell

Check import format using isort
ERROR: /home/travis/build/pandas-dev/pandas/pandas/io/pytables.py Imports are incorrectly sorted
Check import format using isort DONE
The command "ci/code_checks.sh" exited with 1

You should run::
jschendel marked this conversation as resolved.
Show resolved Hide resolved

isort pandas/io/pytables.py

to automatically format imports correctly. This will modify your local copy of the files.

The `--recursive` flag can be passed to sort all files in a directory.

You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.

Backwards Compatibility
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1078,6 +1126,8 @@ or a new keyword argument (`example <https://github.com/pandas-dev/pandas/blob/v
Contributing your changes to *pandas*
=====================================

.. _contributing.commit-code:

Committing your code
--------------------

Expand Down Expand Up @@ -1122,6 +1172,8 @@ Now you can commit your changes in your local repository::

git commit -m

.. _contributing.push-code:

Pushing your changes
--------------------

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ exclude_lines =
[coverage:html]
directory = coverage_html_report

# To be kept consistent with "Import Formatting" section in contributing.rst
[isort]
known_pre_core=pandas._libs,pandas.util._*,pandas.compat,pandas.errors
known_dtypes=pandas.core.dtypes
Expand Down