Skip to content

DOC: Explicitly include "private" ExtensionArray methods in API docs #27279

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
Show file tree
Hide file tree
Changes from 3 commits
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
27 changes: 26 additions & 1 deletion doc/source/reference/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,35 @@ objects.
api.extensions.register_series_accessor
api.extensions.register_index_accessor
api.extensions.ExtensionDtype
api.extensions.ExtensionArray

.. autosummary::
:toctree: api/
:template: autosummary/class_without_autosummary.rst

api.extensions.ExtensionArray
arrays.PandasArray

.. We need this autosummary so that methods and attributes are generated.
.. Separate block, since they aren't classes.

.. autosummary::
:toctree: api/

api.extensions.ExtensionArray._values_for_factorize
api.extensions.ExtensionArray.argsort
api.extensions.ExtensionArray.astype
api.extensions.ExtensionArray.copy
api.extensions.ExtensionArray.dropna
api.extensions.ExtensionArray.factorize
api.extensions.ExtensionArray.fillna
api.extensions.ExtensionArray.isna
api.extensions.ExtensionArray.ravel
api.extensions.ExtensionArray.repeat
api.extensions.ExtensionArray.searchsorted
api.extensions.ExtensionArray.shift
api.extensions.ExtensionArray.take
api.extensions.ExtensionArray.unique
api.extensions.ExtensionArray.dtype
api.extensions.ExtensionArray.nbytes
api.extensions.ExtensionArray.ndim
api.extensions.ExtensionArray.shape
40 changes: 34 additions & 6 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ class ExtensionArray:

.. versionadded:: 0.23.0

Attributes
----------
dtype
nbytes
ndim
shape

Methods
-------
argsort
astype
copy
dropna
factorize
fillna
isna
ravel
repeat
searchsorted
shift
take
unique
_values_for_factorize

Notes
-----
The interface includes the following abstract methods that must be
Expand Down Expand Up @@ -654,7 +678,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ABCExtensionArra

See Also
--------
pandas.factorize : Top-level factorize method that dispatches here.
factorize : Top-level factorize method that dispatches here.

Notes
-----
Expand Down Expand Up @@ -778,18 +802,18 @@ def take(
When `indices` contains negative values other than ``-1``
and `allow_fill` is True.

See Also
--------
numpy.take
api.extensions.take
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 leave the pandas. here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorisvandenbossche
I've removed pandas. to resolve the Docstring validation error. From CI:

pandas/core/arrays/base.py(770,): error SA05: pandas.api.extensions.ExtensionArray.take: pandas.api.extensions.take in `See Also` section does not need `pandas` prefix, use api.extensions.take instead.

What do you recommend to do?

Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike this listing rule in this case. I believe it's to ensure we consistently do things like DataFrame.merge instead of pandas.DataFrame.merge.

But I think the (redundant) namespacing here is helpful here since I wouldn't immediately associate api... with pandas.api....

Regardless, for now we can just please the linter.


Notes
-----
ExtensionArray.take is called by ``Series.__getitem__``, ``.loc``,
``iloc``, when `indices` is a sequence of values. Additionally,
it's called by :meth:`Series.reindex`, or any other method
that causes realignment, with a `fill_value`.

See Also
--------
numpy.take
pandas.api.extensions.take

Examples
--------
Here's an example implementation, which relies on casting the
Expand Down Expand Up @@ -904,6 +928,10 @@ def ravel(self, order="C") -> ABCExtensionArray:
----------
order : {None, 'C', 'F', 'A', 'K'}, default 'C'

Returns
-------
ExtensionArray

Notes
-----
- Because ExtensionArrays are 1D-only, this is a no-op.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ def _is_dtype_compat(self, other):

def equals(self, other):
"""
Determine if two CategorialIndex objects contain the same elements.
Determine if two CategoricalIndex objects contain the same elements.

Returns
-------
bool
If two CategorialIndex objects have equal elements True,
If two CategoricalIndex objects have equal elements True,
otherwise False.
"""
if self.is_(other):
Expand Down