diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 778c12c11ce93..f872aaec6ec76 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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 \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 0be97edf84d16..ae39281bb1fa2 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -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])) + + [1*, 2*, 3*, 4*] + Length: 4, dtype: int64 """ if boxed: return str