From 553eaee04a4c0e349304aa47a052d4bc29196b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Wed, 26 Jul 2023 13:01:20 +0200 Subject: [PATCH] Examples ExtensionArray, hash_array ... --- ci/code_checks.sh | 6 ------ pandas/core/arrays/base.py | 16 ++++++++++++++++ pandas/core/util/hashing.py | 14 ++++++++++++++ scripts/validate_docstrings.py | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 019693ffa089e..15e24998944cb 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -64,7 +64,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.errors.IncompatibilityWarning \ - pandas.errors.NoBufferPresent \ pandas.errors.OptionError \ pandas.errors.PerformanceWarning \ pandas.errors.PyperclipException \ @@ -78,15 +77,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.io.stata.StataWriter.write_file \ pandas.plotting.deregister_matplotlib_converters \ pandas.plotting.register_matplotlib_converters \ - pandas.util.hash_array \ - pandas.util.hash_pandas_object \ - pandas_object \ pandas.api.indexers.BaseIndexer \ pandas.api.indexers.VariableOffsetWindowIndexer \ pandas.api.extensions.ExtensionDtype \ pandas.api.extensions.ExtensionArray \ pandas.arrays.NumpyExtensionArray \ - pandas.api.extensions.ExtensionArray._concat_same_type \ pandas.api.extensions.ExtensionArray._formatter \ pandas.api.extensions.ExtensionArray._from_factorized \ pandas.api.extensions.ExtensionArray._from_sequence \ @@ -95,7 +90,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.api.extensions.ExtensionArray._reduce \ pandas.api.extensions.ExtensionArray._values_for_factorize \ pandas.api.extensions.ExtensionArray.interpolate \ - pandas.api.extensions.ExtensionArray.ravel \ RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 265d8aa41f53f..0be97edf84d16 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1565,6 +1565,13 @@ def ravel(self, order: Literal["C", "F", "A", "K"] | None = "C") -> ExtensionArr ----- - Because ExtensionArrays are 1D-only, this is a no-op. - The "order" argument is ignored, is for compatibility with NumPy. + + Examples + -------- + >>> pd.array([1, 2, 3]).ravel() + + [1, 2, 3] + Length: 3, dtype: Int64 """ return self @@ -1580,6 +1587,15 @@ def _concat_same_type(cls, to_concat: Sequence[Self]) -> Self: Returns ------- ExtensionArray + + Examples + -------- + >>> arr1 = pd.array([1, 2, 3]) + >>> arr2 = pd.array([4, 5, 6]) + >>> pd.arrays.IntegerArray._concat_same_type([arr1, arr2]) + + [1, 2, 3, 4, 5, 6] + Length: 6, dtype: Int64 """ # Implementer note: this method will only be called with a sequence of # ExtensionArrays of this class and with the same dtype as self. This diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index 676490693b121..4933de3212581 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -106,6 +106,14 @@ def hash_pandas_object( Returns ------- Series of uint64, same length as the object + + Examples + -------- + >>> pd.util.hash_pandas_object(pd.Series([1, 2, 3])) + 0 14639053686158035780 + 1 3869563279212530728 + 2 393322362522515241 + dtype: uint64 """ from pandas import Series @@ -246,6 +254,12 @@ def hash_array( ------- ndarray[np.uint64, ndim=1] Hashed values, same length as the vals. + + Examples + -------- + >>> pd.util.hash_array(np.array([1, 2, 3])) + array([ 6238072747940578789, 15839785061582574730, 2185194620014831856], + dtype=uint64) """ if not hasattr(vals, "dtype"): raise TypeError("must pass a ndarray-like") diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 55d0fe614468d..edf79b1eddacd 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -51,6 +51,7 @@ "Styler.loader", "errors.InvalidComparison", "errors.LossySetitemError", + "errors.NoBufferPresent", } PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"] ERROR_MSGS = {