From 6294bf5f3cff7d2e96fb51a924395b4e2c2695e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 22 May 2023 17:10:11 +0200 Subject: [PATCH 1/3] Examples --- ci/code_checks.sh | 7 ------- pandas/core/arrays/floating.py | 18 ++++++++++++------ pandas/core/arrays/interval.py | 27 +++++++++++++++++++++++---- pandas/core/base.py | 14 ++++++++++++++ pandas/core/indexes/base.py | 12 ++++++++++++ 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 4eecee4be4731..64c5b735fdc8d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -170,8 +170,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Period.asfreq \ pandas.Period.now \ pandas.arrays.PeriodArray \ - pandas.arrays.IntervalArray.from_arrays \ - pandas.arrays.IntervalArray.to_tuples \ pandas.Int8Dtype \ pandas.Int16Dtype \ pandas.Int32Dtype \ @@ -181,8 +179,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.UInt32Dtype \ pandas.UInt64Dtype \ pandas.NA \ - pandas.Float32Dtype \ - pandas.Float64Dtype \ pandas.CategoricalDtype.categories \ pandas.CategoricalDtype.ordered \ pandas.Categorical.dtype \ @@ -258,9 +254,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.util.hash_pandas_object \ pandas_object \ pandas.api.interchange.from_dataframe \ - pandas.Index.T \ - pandas.Index.memory_usage \ - pandas.Index.copy \ pandas.Index.drop \ pandas.Index.identical \ pandas.Index.insert \ diff --git a/pandas/core/arrays/floating.py b/pandas/core/arrays/floating.py index c268b25bf4a59..48bb80530036c 100644 --- a/pandas/core/arrays/floating.py +++ b/pandas/core/arrays/floating.py @@ -127,13 +127,19 @@ class FloatingArray(NumericArray): This dtype uses ``pd.NA`` as missing value indicator. -Attributes ----------- -None +Examples +-------- +For Float32Dtype: -Methods -------- -None +>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float32Dtype()) +>>> ser.dtype +Float32Dtype() + +For Float64Dtype: + +>>> ser = pd.Series([2.25, pd.NA], dtype=pd.Float64Dtype()) +>>> ser.dtype +Float64Dtype() """ # create the Dtype diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 2303f8334c07c..2842d8267b7c6 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -509,6 +509,8 @@ def from_breaks( "name": "", "examples": textwrap.dedent( """\ + Examples + -------- >>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3]) [(0, 1], (1, 2], (2, 3]] @@ -1635,9 +1637,8 @@ def __arrow_array__(self, type=None): return pyarrow.ExtensionArray.from_storage(interval_type, storage_array) - _interval_shared_docs[ - "to_tuples" - ] = """ + _interval_shared_docs["to_tuples"] = textwrap.dedent( + """ Return an %(return_type)s of tuples of the form (left, right). Parameters @@ -1651,9 +1652,27 @@ def __arrow_array__(self, type=None): tuples: %(return_type)s %(examples)s\ """ + ) @Appender( - _interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""} + _interval_shared_docs["to_tuples"] + % { + "return_type": "ndarray", + "examples": textwrap.dedent( + """\ + + Examples + -------- + >>> idx = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)]) + >>> idx + + [(0, 1], (1, 2]] + Length: 2, dtype: interval[int64, right] + >>> idx.to_tuples() + array([(0, 1), (1, 2)], dtype=object) + """ + ), + } ) def to_tuples(self, na_tuple: bool = True) -> np.ndarray: tuples = com.asarray_tuplesafe(zip(self._left, self._right)) diff --git a/pandas/core/base.py b/pandas/core/base.py index d939c0d454de8..0d99118d25e96 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -300,6 +300,8 @@ def transpose(self, *args, **kwargs) -> Self: Examples -------- + For Series: + >>> s = pd.Series(['Ant', 'Bear', 'Cow']) >>> s 0 Ant @@ -311,6 +313,12 @@ def transpose(self, *args, **kwargs) -> Self: 1 Bear 2 Cow dtype: object + + For Index: + + >>> idx = pd.Index([1, 2, 3]) + >>> idx.T + Index([1, 2, 3], dtype='int64') """, ) @@ -1088,6 +1096,12 @@ def _memory_usage(self, deep: bool = False) -> int: ----- Memory usage does not include memory consumed by elements that are not components of the array if deep=False or if used on PyPy + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx.memory_usage() + 24 """ if hasattr(self.array, "memory_usage"): return self.array.memory_usage( # pyright: ignore[reportGeneralTypeIssues] diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e7d975068dd70..92d221312fc77 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1221,6 +1221,18 @@ def copy( ----- In most cases, there should be no functional difference from using ``deep``, but if ``deep`` is passed it will attempt to deepcopy. + + Examples + -------- + >>> idx = pd.Index(['a', 'b', 'c']) + >>> new_idx = idx.copy(name="idx2") + >>> ser = pd.Series([1, 2, 3], index=new_idx) + >>> ser + idx2 + a 1 + b 2 + c 3 + dtype: int64 """ name = self._validate_names(name=name, deep=deep)[0] From d74ddc194ec6c8e6ff86a23bc153d9ead00eb031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 22 May 2023 19:05:01 +0200 Subject: [PATCH 2/3] Changed Index.copy --- pandas/core/indexes/base.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 92d221312fc77..174c6625fb779 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1225,14 +1225,9 @@ def copy( Examples -------- >>> idx = pd.Index(['a', 'b', 'c']) - >>> new_idx = idx.copy(name="idx2") - >>> ser = pd.Series([1, 2, 3], index=new_idx) - >>> ser - idx2 - a 1 - b 2 - c 3 - dtype: int64 + >>> new_idx = idx.copy() + >>> idx is new_idx + False """ name = self._validate_names(name=name, deep=deep)[0] From 50b0a4daecdaa5e98228e188cc5735e7a6ca4ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 23 May 2023 09:10:23 +0200 Subject: [PATCH 3/3] Corrected Float32Dtype & Float64Dtype --- pandas/core/arrays/floating.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/arrays/floating.py b/pandas/core/arrays/floating.py index 48bb80530036c..bd3c03f9218d4 100644 --- a/pandas/core/arrays/floating.py +++ b/pandas/core/arrays/floating.py @@ -127,6 +127,14 @@ class FloatingArray(NumericArray): This dtype uses ``pd.NA`` as missing value indicator. +Attributes +---------- +None + +Methods +------- +None + Examples -------- For Float32Dtype: