Skip to content

Commit

Permalink
Isort contributing guide (pandas-dev#23364)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimcmaster1 authored and tm9k1 committed Nov 19, 2018
1 parent c8dbc8c commit d2857e0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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.

.. _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::

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

0 comments on commit d2857e0

Please sign in to comment.