-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
DOC: Various EA docs #20707
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe clarify that those have a default working implementation, but do a |
||
|
||
* 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 | ||
|
@@ -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. | ||
|
There was a problem hiding this comment.
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.