Skip to content

DOC: Various EA docs #20707

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

Merged
merged 2 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions doc/source/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ If you write a custom accessor, make a pull request adding it to our
Extension Types
---------------

.. versionadded:: 0.23.0

.. warning::

The ``ExtensionDtype`` and ``ExtensionArray`` APIs are new and
experimental. They may change between versions without warning.

Pandas defines an interface for implementing data types and arrays that *extend*
NumPy's type system. Pandas itself uses the extension system for some types
that aren't built into NumPy (categorical, period, interval, datetime with
Expand Down Expand Up @@ -106,6 +113,24 @@ by some other storage type, like Python lists.
See the `extension array source`_ for the interface definition. The docstrings
and comments contain guidance for properly implementing the interface.

We provide a test suite for ensuring that your extension arrays satisfy the expected
behavior. To use the test-suite, you must provide several pytest fixtures and inherit
Copy link
Member

Choose a reason for hiding this comment

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

"test-suite" or "test suite" (without the dash)? You use both.

from the base test class. The required fixtures are found in
https://github.com/pandas-dev/pandas/blob/master/pandas/tests/extension/conftest.py.

To use a test, subclass it
Copy link
Member

Choose a reason for hiding this comment

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

Nit: do we want a colon at the end of this sentence?


.. code-block:: python

from pandas.tests.extension import base

class TestConstructors(base.BaseConstructorsTests):
pass


See https://github.com/pandas-dev/pandas/blob/master/pandas/tests/extension/base/__init__.py
for a list of all the tests available.

.. _extension dtype source: https://github.com/pandas-dev/pandas/blob/master/pandas/core/dtypes/base.py
.. _extension array source: https://github.com/pandas-dev/pandas/blob/master/pandas/core/arrays/base.py

Expand Down
2 changes: 1 addition & 1 deletion doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Instructions for installing from source,
`PyPI <http://pypi.python.org/pypi/pandas>`__, `ActivePython <https://www.activestate.com/activepython/downloads>`__, various Linux distributions, or a
`development version <http://github.com/pandas-dev/pandas>`__ are also provided.

.. _install.dropping_27:
.. _install.dropping-27:

Plan for dropping Python 2.7
----------------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version.
.. warning::

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

.. _whatsnew_0230.enhancements:

Expand Down Expand Up @@ -306,8 +306,8 @@ Supplying a ``CategoricalDtype`` will make the categories in each column consist

.. _whatsnew_023.enhancements.extension:

Extending Pandas with Custom Types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Extending Pandas with Custom Types (Experimental)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Pandas now supports storing array-like objects that aren't necessarily 1-D NumPy
arrays as columns in a DataFrame or values in a Series. This allows third-party
Expand Down
16 changes: 12 additions & 4 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class ExtensionArray(object):
with a custom type and will not attempt to coerce them to objects. They
may be stored directly inside a :class:`DataFrame` or :class:`Series`.

.. versionadded:: 0.23.0
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a note about the experimental status in this file as well (eg in module docstring at line 1).


Notes
-----
The interface includes the following abstract methods that must be
implemented by subclasses:

* _constructor_from_sequence
* _from_factorized
* __getitem__
* __len__
* dtype
Expand All @@ -35,6 +38,15 @@ class ExtensionArray(object):
* _can_hold_na
* _formatting_values

Some methods require casting the ExtensionArray to an ndarray of Python
objects, which may be expensive. When performance is a concern, we highly
recommend overriding the following methods.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe clarify that those have a default working implementation, but do a self.astype(object) ?


* fillna
* unique
* factorize / _values_for_factorize
* argsort / _values_for_argsort

This class does not inherit from 'abc.ABCMeta' for performance reasons.
Methods and properties required by the interface raise
``pandas.errors.AbstractMethodError`` and no ``register`` method is
Expand All @@ -50,10 +62,6 @@ class ExtensionArray(object):
by some other storage type, like Python lists. Pandas makes no
assumptions on how the data are stored, just that it can be converted
to a NumPy array.

Extension arrays should be able to be constructed with instances of
the class, i.e. ``ExtensionArray(extension_array)`` should return
an instance, not error.
"""
# '_typ' is for pandas.core.dtypes.generic.ABCExtensionArray.
# Don't override this.
Expand Down