Skip to content

Commit

Permalink
DOC: Fixing EX01 - Added examples (#54267)
Browse files Browse the repository at this point in the history
* Example ExtensionArray._formatter

* Added if boxed...
  • Loading branch information
DeaMariaLeon authored Jul 26, 2023
1 parent 4f55280 commit 577bb72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.api.extensions.ExtensionDtype \
pandas.api.extensions.ExtensionArray \
pandas.arrays.NumpyExtensionArray \
pandas.api.extensions.ExtensionArray._formatter \
pandas.api.extensions.ExtensionArray._from_factorized \
pandas.api.extensions.ExtensionArray._from_sequence \
pandas.api.extensions.ExtensionArray._from_sequence_of_strings \
Expand Down
10 changes: 10 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,16 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
returns a string. By default, :func:`repr` is used
when ``boxed=False`` and :func:`str` is used when
``boxed=True``.
Examples
--------
>>> class MyExtensionArray(pd.arrays.NumpyExtensionArray):
... def _formatter(self, boxed=False):
... return lambda x: '*' + str(x) + '*' if boxed else repr(x) + '*'
>>> MyExtensionArray(np.array([1, 2, 3, 4]))
<MyExtensionArray>
[1*, 2*, 3*, 4*]
Length: 4, dtype: int64
"""
if boxed:
return str
Expand Down

0 comments on commit 577bb72

Please sign in to comment.