Skip to content

Commit e4ea6c9

Browse files
committed
DOC: Move import conventions from wiki to docs pandas-dev#30808
1 parent d3f0856 commit e4ea6c9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

doc/source/development/code_style.rst

+39
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,42 @@ For example:
127127
128128
value = str
129129
f"Unknown recived type, got: '{type(value).__name__}'"
130+
131+
132+
Imports (aim for absolute)
133+
==========================
134+
135+
In Python 3, absolute imports are recommended. In absolute import doing something
136+
like ``import string`` will import the string module rather than ``string.py``
137+
in the same directory. As much as possible, you should try to write out
138+
absolute imports that show the whole import chain from toplevel pandas.
139+
140+
For example:
141+
142+
**Good:**
143+
144+
.. code-block:: python
145+
146+
import pandas.core.common as com
147+
148+
Explicit relative imports are also supported in Python 3. In test code, it might
149+
be easier to just reference local variables with explicit relative imports
150+
(that start with ``.``) for clarity, but in other code better to be absolute.
151+
152+
For example:
153+
154+
**Good (Test Code Only):**
155+
156+
.. code-block:: python
157+
158+
from .common import test_base
159+
160+
Implicit relative imports should never be used and is removed in Python 3.
161+
162+
For example:
163+
164+
**Wrong:**
165+
166+
.. code-block:: python
167+
168+
from common import test_base

0 commit comments

Comments
 (0)