Skip to content

Commit 23bc217

Browse files
TomAugspurgerjreback
authored andcommitted
DOC: Various EA docs (#20707)
1 parent 3a2e9e6 commit 23bc217

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

doc/source/extending.rst

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ If you write a custom accessor, make a pull request adding it to our
5757
Extension Types
5858
---------------
5959

60+
.. versionadded:: 0.23.0
61+
62+
.. warning::
63+
64+
The ``ExtensionDtype`` and ``ExtensionArray`` APIs are new and
65+
experimental. They may change between versions without warning.
66+
6067
Pandas defines an interface for implementing data types and arrays that *extend*
6168
NumPy's type system. Pandas itself uses the extension system for some types
6269
that aren't built into NumPy (categorical, period, interval, datetime with
@@ -106,6 +113,24 @@ by some other storage type, like Python lists.
106113
See the `extension array source`_ for the interface definition. The docstrings
107114
and comments contain guidance for properly implementing the interface.
108115

116+
We provide a test suite for ensuring that your extension arrays satisfy the expected
117+
behavior. To use the test suite, you must provide several pytest fixtures and inherit
118+
from the base test class. The required fixtures are found in
119+
https://github.com/pandas-dev/pandas/blob/master/pandas/tests/extension/conftest.py.
120+
121+
To use a test, subclass it:
122+
123+
.. code-block:: python
124+
125+
from pandas.tests.extension import base
126+
127+
class TestConstructors(base.BaseConstructorsTests):
128+
pass
129+
130+
131+
See https://github.com/pandas-dev/pandas/blob/master/pandas/tests/extension/base/__init__.py
132+
for a list of all the tests available.
133+
109134
.. _extension dtype source: https://github.com/pandas-dev/pandas/blob/master/pandas/core/dtypes/base.py
110135
.. _extension array source: https://github.com/pandas-dev/pandas/blob/master/pandas/core/arrays/base.py
111136

doc/source/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Instructions for installing from source,
1515
`PyPI <http://pypi.python.org/pypi/pandas>`__, `ActivePython <https://www.activestate.com/activepython/downloads>`__, various Linux distributions, or a
1616
`development version <http://github.com/pandas-dev/pandas>`__ are also provided.
1717

18-
.. _install.dropping_27:
18+
.. _install.dropping-27:
1919

2020
Plan for dropping Python 2.7
2121
----------------------------

doc/source/whatsnew/v0.23.0.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ version.
1111
.. warning::
1212

1313
Starting January 1, 2019, pandas feature releases will support Python 3 only.
14-
See :ref:`here <install.dropping_27>` for more.
14+
See :ref:`install.dropping-27` for more.
1515

1616
.. _whatsnew_0230.enhancements:
1717

@@ -335,8 +335,8 @@ Supplying a ``CategoricalDtype`` will make the categories in each column consist
335335

336336
.. _whatsnew_023.enhancements.extension:
337337

338-
Extending Pandas with Custom Types
339-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
338+
Extending Pandas with Custom Types (Experimental)
339+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
340340

341341
Pandas now supports storing array-like objects that aren't necessarily 1-D NumPy
342342
arrays as columns in a DataFrame or values in a Series. This allows third-party

pandas/core/arrays/base.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
"""An interface for extending pandas with custom arrays."""
1+
"""An interface for extending pandas with custom arrays.
2+
3+
.. warning::
4+
5+
This is an experimental API and subject to breaking changes
6+
without warning.
7+
"""
28
import numpy as np
39

410
from pandas.errors import AbstractMethodError
@@ -14,12 +20,15 @@ class ExtensionArray(object):
1420
with a custom type and will not attempt to coerce them to objects. They
1521
may be stored directly inside a :class:`DataFrame` or :class:`Series`.
1622
23+
.. versionadded:: 0.23.0
24+
1725
Notes
1826
-----
1927
The interface includes the following abstract methods that must be
2028
implemented by subclasses:
2129
2230
* _constructor_from_sequence
31+
* _from_factorized
2332
* __getitem__
2433
* __len__
2534
* dtype
@@ -30,11 +39,21 @@ class ExtensionArray(object):
3039
* _concat_same_type
3140
3241
Some additional methods are available to satisfy pandas' internal, private
33-
block API.
42+
block API:
3443
3544
* _can_hold_na
3645
* _formatting_values
3746
47+
Some methods require casting the ExtensionArray to an ndarray of Python
48+
objects with ``self.astype(object)``, which may be expensive. When
49+
performance is a concern, we highly recommend overriding the following
50+
methods:
51+
52+
* fillna
53+
* unique
54+
* factorize / _values_for_factorize
55+
* argsort / _values_for_argsort
56+
3857
This class does not inherit from 'abc.ABCMeta' for performance reasons.
3958
Methods and properties required by the interface raise
4059
``pandas.errors.AbstractMethodError`` and no ``register`` method is
@@ -50,10 +69,6 @@ class ExtensionArray(object):
5069
by some other storage type, like Python lists. Pandas makes no
5170
assumptions on how the data are stored, just that it can be converted
5271
to a NumPy array.
53-
54-
Extension arrays should be able to be constructed with instances of
55-
the class, i.e. ``ExtensionArray(extension_array)`` should return
56-
an instance, not error.
5772
"""
5873
# '_typ' is for pandas.core.dtypes.generic.ABCExtensionArray.
5974
# Don't override this.

0 commit comments

Comments
 (0)