Skip to content

Commit 577bb72

Browse files
authored
DOC: Fixing EX01 - Added examples (#54267)
* Example ExtensionArray._formatter * Added if boxed...
1 parent 4f55280 commit 577bb72

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8585
pandas.api.extensions.ExtensionDtype \
8686
pandas.api.extensions.ExtensionArray \
8787
pandas.arrays.NumpyExtensionArray \
88-
pandas.api.extensions.ExtensionArray._formatter \
8988
pandas.api.extensions.ExtensionArray._from_factorized \
9089
pandas.api.extensions.ExtensionArray._from_sequence \
9190
pandas.api.extensions.ExtensionArray._from_sequence_of_strings \

pandas/core/arrays/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,16 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], str | None]:
15271527
returns a string. By default, :func:`repr` is used
15281528
when ``boxed=False`` and :func:`str` is used when
15291529
``boxed=True``.
1530+
1531+
Examples
1532+
--------
1533+
>>> class MyExtensionArray(pd.arrays.NumpyExtensionArray):
1534+
... def _formatter(self, boxed=False):
1535+
... return lambda x: '*' + str(x) + '*' if boxed else repr(x) + '*'
1536+
>>> MyExtensionArray(np.array([1, 2, 3, 4]))
1537+
<MyExtensionArray>
1538+
[1*, 2*, 3*, 4*]
1539+
Length: 4, dtype: int64
15301540
"""
15311541
if boxed:
15321542
return str

0 commit comments

Comments
 (0)