Skip to content

Commit 0fe97bc

Browse files
alimcmaster1jreback
authored andcommitted
Isort contributing guide (#23364)
1 parent 471fb0e commit 0fe97bc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

doc/source/contributing.rst

+52
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,54 @@ Alternatively, you can install the ``grep`` and ``xargs`` commands via the
612612
`MinGW <http://www.mingw.org/>`__ toolchain, and it will allow you to run the
613613
commands above.
614614

615+
.. _contributing.import-formatting:
616+
617+
Import Formatting
618+
~~~~~~~~~~~~~~~~~
619+
*pandas* uses `isort <https://pypi.org/project/isort/>`__ to standardise import
620+
formatting across the codebase.
621+
622+
A guide to import layout as per pep8 can be found `here <https://www.python.org/dev/peps/pep-0008/#imports/>`__.
623+
624+
A summary of our current import sections ( in order ):
625+
626+
* Future
627+
* Python Standard Library
628+
* Third Party
629+
* ``pandas._libs``, ``pandas.compat``, ``pandas.util._*``, ``pandas.errors`` (largely not dependent on ``pandas.core``)
630+
* ``pandas.core.dtypes`` (largely not dependent on the rest of ``pandas.core``)
631+
* Rest of ``pandas.core.*``
632+
* Non-core ``pandas.io``, ``pandas.plotting``, ``pandas.tseries``
633+
* Local application/library specific imports
634+
635+
Imports are alphabetically sorted within these sections.
636+
637+
638+
As part of :ref:`Continuous Integration <contributing.ci>` checks we run::
639+
640+
isort --recursive --check-only pandas
641+
642+
to check that imports are correctly formatted as per the `setup.cfg`.
643+
644+
If you see output like the below in :ref:`Continuous Integration <contributing.ci>` checks:
645+
646+
.. code-block:: shell
647+
648+
Check import format using isort
649+
ERROR: /home/travis/build/pandas-dev/pandas/pandas/io/pytables.py Imports are incorrectly sorted
650+
Check import format using isort DONE
651+
The command "ci/code_checks.sh" exited with 1
652+
653+
You should run::
654+
655+
isort pandas/io/pytables.py
656+
657+
to automatically format imports correctly. This will modify your local copy of the files.
658+
659+
The `--recursive` flag can be passed to sort all files in a directory.
660+
661+
You can then verify the changes look ok, then git :ref:`commit <contributing.commit-code>` and :ref:`push <contributing.push-code>`.
662+
615663
Backwards Compatibility
616664
~~~~~~~~~~~~~~~~~~~~~~~
617665

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

1129+
.. _contributing.commit-code:
1130+
10811131
Committing your code
10821132
--------------------
10831133

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

11231173
git commit -m
11241174

1175+
.. _contributing.push-code:
1176+
11251177
Pushing your changes
11261178
--------------------
11271179

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ exclude_lines =
7676
[coverage:html]
7777
directory = coverage_html_report
7878

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

0 commit comments

Comments
 (0)