From d489b6b6c8944c56c3da0cf2e5e0715c828fac61 Mon Sep 17 00:00:00 2001 From: merlinymy Date: Wed, 21 Feb 2024 01:53:54 -0600 Subject: [PATCH 01/29] Add missing docstring for pandas.Index.empty --- ci/code_checks.sh | 1 - pandas/core/base.py | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 04c3ff3a42971..d5082ab65e067 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -147,7 +147,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DatetimeIndex.freq\ pandas.ExcelFile.book\ pandas.ExcelFile.sheet_names\ - pandas.Index.empty\ pandas.Index.names\ pandas.Index.view\ pandas.IntervalIndex.left\ diff --git a/pandas/core/base.py b/pandas/core/base.py index 7a3d6cb866ea5..0b88680466278 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -673,6 +673,33 @@ def to_numpy( @final @property def empty(self) -> bool: + """ + Check if the Index is empty. + + An Index is considered empty if it has no elements. This property can be + useful for quickly checking the state of an Index, especially in data + processing and analysis workflows where handling of empty datasets might + be required. + + Returns + ------- + bool + True if the Index is empty, False otherwise. + + See Also + -------- + size : Return the number of elements in the Index. + + Examples + -------- + >>> index = pd.Index([]) + >>> index.empty + True + + >>> non_empty_index = pd.Index([1, 2, 3]) + >>> non_empty_index.empty + False + """ return not self.size @doc(op="max", oppose="min", value="largest") From f855eb5a1e3059782c3e177b923cbf4abf72931f Mon Sep 17 00:00:00 2001 From: merlinymy Date: Wed, 21 Feb 2024 02:48:38 -0600 Subject: [PATCH 02/29] Add docstring for pandas.Index.names --- ci/code_checks.sh | 1 - pandas/core/indexes/base.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index d5082ab65e067..0483dbe031e38 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -147,7 +147,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DatetimeIndex.freq\ pandas.ExcelFile.book\ pandas.ExcelFile.sheet_names\ - pandas.Index.names\ pandas.Index.view\ pandas.IntervalIndex.left\ pandas.IntervalIndex.length\ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c17e01b85fa84..dfd9117dc7a28 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1735,6 +1735,35 @@ def _get_default_index_names( return names def _get_names(self) -> tuple[Hashable | None, ...]: + """ + Retrieve the names associated with the object. + + This method returns a tuple containing the name of the object. + It's primarily intended for internal use. + + Returns + ------- + tuple[Hashable | None, ...] + A tuple containing the object's name, or None if the object does not have a name. + + See Also + -------- + _set_names : Set new names on index. + + Examples + -------- + Create an index with a name and retrieve its names: + + >>> index = pd.Index([1, 2, 3], name='example_name') + >>> index.names + ('example_name',) + + If the index does not have a name set: + + >>> index = pd.Index([1, 2, 3]) + >>> index.names + (None,) + """ return (self.name,) def _set_names(self, values, *, level=None) -> None: From bcce3ff6e4fdb01f03e7faca992d0d92a6c994e9 Mon Sep 17 00:00:00 2001 From: merlinymy Date: Wed, 21 Feb 2024 03:24:06 -0600 Subject: [PATCH 03/29] Add docstring for pandas.Index.view --- ci/code_checks.sh | 1 - pandas/core/indexes/base.py | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 0483dbe031e38..2ba502df58568 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -147,7 +147,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DatetimeIndex.freq\ pandas.ExcelFile.book\ pandas.ExcelFile.sheet_names\ - pandas.Index.view\ pandas.IntervalIndex.left\ pandas.IntervalIndex.length\ pandas.IntervalIndex.mid\ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index dfd9117dc7a28..4971939acb565 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1011,6 +1011,66 @@ def ravel(self, order: str_t = "C") -> Self: return self[:] def view(self, cls=None): + """ + Return a view of the Index with the specified dtype or a new Index instance. + + This method returns a view of the calling Index object if no arguments are + provided. If a dtype is specified through the `cls` argument, it attempts + to return a view of the Index with the specified dtype. Note that viewing + the Index as a different dtype reinterprets the underlying data, which can + lead to unexpected results for non-numeric or incompatible dtype conversions. + + Parameters + ---------- + cls : dtype or None, optional + The dtype for the returned view of the Index. If None (default), a view + of the calling Index is returned without altering the dtype. If a numeric + dtype is specified, the method attempts to reinterpret the Index data as + the specified dtype. + + Returns + ------- + Index or ndarray + A view of the Index. If `cls` is None, the returned object is an Index + view with the same dtype as the calling object. If a numeric `cls` is + specified, the behavior depends on the compatibility of the conversion: + - If the conversion is valid, an ndarray view with the new dtype is returned. + - If `cls` specifies a dtype that leads to an incompatible conversion, + a ValueError is raised. + + Raises + ------ + ValueError + If attempting to change to a dtype in a way that is not compatible with + the original dtype's memory layout, for example, viewing an 'int64' Index + as 'str'. + + Warnings + -------- + FutureWarning + Directly passing a dtype to `view` that results in an incompatible memory + reinterpretation will raise an error in a future version. + + See Also + -------- + copy: Returns a copy of the Index. + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx.view() + Index([1, 2, 3], dtype='int64') + + Viewing as 'int32' reinterprets the memory, which may lead to unexpected behavior: + + >>> idx.view('int32') + array([1, 0, 2, 0, 3, 0], dtype=int32) + + Attempting to view as 'str' is not supported and raises an error: + + >>> idx.view('str') + ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype + """ # we need to see if we are subclassing an # index type here if cls is not None and not hasattr(cls, "_typ"): From 4b79d59269e2c89b5d08058f2c6a6c2bd8b59acf Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:24:18 +0100 Subject: [PATCH 04/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 050df2466ec32..a5bf194daa01e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1050,7 +1050,6 @@ def view(self, cls=None): FutureWarning Directly passing a dtype to `view` that results in an incompatible memory reinterpretation will raise an error in a future version. - See Also -------- copy: Returns a copy of the Index. From 0fb33e4f51272f3faf547f32583e866b48cfe8aa Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:24:27 +0100 Subject: [PATCH 05/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a5bf194daa01e..683269cc80d29 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1796,7 +1796,6 @@ def _get_default_index_names( def _get_names(self) -> tuple[Hashable | None, ...]: """ Retrieve the names associated with the object. - This method returns a tuple containing the name of the object. It's primarily intended for internal use. From 07abdbc6101608864f6ebbffe50ca47ab8b1e1c7 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:24:33 +0100 Subject: [PATCH 06/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 683269cc80d29..2f91853f06364 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1803,7 +1803,6 @@ def _get_names(self) -> tuple[Hashable | None, ...]: ------- tuple[Hashable | None, ...] A tuple containing the object's name, or None if the object does not have a name. - See Also -------- _set_names : Set new names on index. From 59e25f640f20eb3354e836e66cc400702c525b27 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:24:40 +0100 Subject: [PATCH 07/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2f91853f06364..8ed48997bbc57 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1803,10 +1803,6 @@ def _get_names(self) -> tuple[Hashable | None, ...]: ------- tuple[Hashable | None, ...] A tuple containing the object's name, or None if the object does not have a name. - See Also - -------- - _set_names : Set new names on index. - Examples -------- Create an index with a name and retrieve its names: From e7f928539a4833aec6b0dcf1221ca14e9105a345 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:31:57 +0100 Subject: [PATCH 08/29] Update pandas/core/base.py --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index c4899fdd28e36..0142338dfe993 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -686,7 +686,7 @@ def empty(self) -> bool: Returns ------- bool - True if the Index is empty, False otherwise. + ``True`` if the Index is empty, ``False`` otherwise. See Also -------- From 6cb9cd882d858ba5118134d432e4c5beb97a50e9 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:04 +0100 Subject: [PATCH 09/29] Update pandas/core/base.py --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 0142338dfe993..e963b90925ea1 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -690,7 +690,7 @@ def empty(self) -> bool: See Also -------- - size : Return the number of elements in the Index. + Index.size : Return the number of elements in the Index. Examples -------- From a2e456a2205f751e00c980abbf0b3e15d60d04a5 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:15 +0100 Subject: [PATCH 10/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 8ed48997bbc57..36bbaee2ddd84 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1022,7 +1022,7 @@ def view(self, cls=None): Parameters ---------- - cls : dtype or None, optional + cls : dtype, optional The dtype for the returned view of the Index. If None (default), a view of the calling Index is returned without altering the dtype. If a numeric dtype is specified, the method attempts to reinterpret the Index data as From 92302df255dcf60b6db3a784c4200dd52d36c740 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:22 +0100 Subject: [PATCH 11/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 36bbaee2ddd84..d77e095aa25ae 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1023,7 +1023,7 @@ def view(self, cls=None): Parameters ---------- cls : dtype, optional - The dtype for the returned view of the Index. If None (default), a view + The dtype for the returned view of the Index. If ``None`` (default), a view of the calling Index is returned without altering the dtype. If a numeric dtype is specified, the method attempts to reinterpret the Index data as the specified dtype. From 4babd7dd3078b15802d55494ba7c1b707aeda297 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:28 +0100 Subject: [PATCH 12/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d77e095aa25ae..19f75e30cd52f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1052,7 +1052,7 @@ def view(self, cls=None): reinterpretation will raise an error in a future version. See Also -------- - copy: Returns a copy of the Index. + copy : Returns a copy of the Index. Examples -------- From 1e188bc3386c9bc8a229fb6df17ac4f1d6d46115 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:35 +0100 Subject: [PATCH 13/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 19f75e30cd52f..fbde632730e33 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1045,11 +1045,6 @@ def view(self, cls=None): the original dtype's memory layout, for example, viewing an 'int64' Index as 'str'. - Warnings - -------- - FutureWarning - Directly passing a dtype to `view` that results in an incompatible memory - reinterpretation will raise an error in a future version. See Also -------- copy : Returns a copy of the Index. From 79a009a7e3184aa9407e64a3038ad2b31ff565b7 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 20:32:41 +0100 Subject: [PATCH 14/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fbde632730e33..5f31ce9d6e9f4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1059,11 +1059,6 @@ def view(self, cls=None): >>> idx.view('int32') array([1, 0, 2, 0, 3, 0], dtype=int32) - - Attempting to view as 'str' is not supported and raises an error: - - >>> idx.view('str') - ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype """ # we need to see if we are subclassing an # index type here From ee928eab824706891508148d94ea89064f954383 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 23:57:09 +0100 Subject: [PATCH 15/29] Update pandas/core/base.py --- pandas/core/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index e963b90925ea1..927d87a4f5b34 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -687,7 +687,6 @@ def empty(self) -> bool: ------- bool ``True`` if the Index is empty, ``False`` otherwise. - See Also -------- Index.size : Return the number of elements in the Index. From e16c557d9857c6e0a888aabb5e8471f4aaef8980 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Tue, 5 Mar 2024 23:58:33 +0100 Subject: [PATCH 16/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 50ff5eb1323ab..040d76a6ba140 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1793,6 +1793,7 @@ def _get_names(self) -> tuple[Hashable | None, ...]: ------- tuple[Hashable | None, ...] A tuple containing the object's name, or None if the object does not have a name. + Examples -------- Create an index with a name and retrieve its names: From fd90389668a54e54115bab5fd07da5dafc51059b Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 6 Mar 2024 15:52:42 +0100 Subject: [PATCH 17/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 040d76a6ba140..bd7345333b582 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1786,7 +1786,7 @@ def _get_default_index_names( def _get_names(self) -> tuple[Hashable | None, ...]: """ Retrieve the names associated with the object. - This method returns a tuple containing the name of the object. + This method returns a tuple containing the name of the object. It's primarily intended for internal use. Returns From bf8761007fa2f66cad071034f3b9896ca273f07e Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 6 Mar 2024 15:52:49 +0100 Subject: [PATCH 18/29] Update pandas/core/base.py --- pandas/core/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 927d87a4f5b34..eaf243b48165f 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -678,9 +678,9 @@ def empty(self) -> bool: """ Check if the Index is empty. - An Index is considered empty if it has no elements. This property can be - useful for quickly checking the state of an Index, especially in data - processing and analysis workflows where handling of empty datasets might + An Index is considered empty if it has no elements. This property can be + useful for quickly checking the state of an Index, especially in data + processing and analysis workflows where handling of empty datasets might be required. Returns From 7d8a29520097c0cba13721c318909ca99984b639 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 6 Mar 2024 15:52:56 +0100 Subject: [PATCH 19/29] Update pandas/core/base.py --- pandas/core/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index eaf243b48165f..ee0214d979900 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -687,6 +687,7 @@ def empty(self) -> bool: ------- bool ``True`` if the Index is empty, ``False`` otherwise. + See Also -------- Index.size : Return the number of elements in the Index. From ca55f90a0d948c529fdcdf4b81043617b855590a Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Thu, 14 Mar 2024 22:29:48 +0100 Subject: [PATCH 20/29] Update pandas/core/base.py --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index cb44de0897275..a889416f8ec86 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -675,7 +675,7 @@ def to_numpy( @final @property def empty(self) -> bool: - """ + """ Check if the Index is empty. An Index is considered empty if it has no elements. This property can be From 06e88a4e4d9f1dfad50ce6b8603bb0dc410b31ed Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sat, 16 Mar 2024 16:49:54 +0100 Subject: [PATCH 21/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index eeb482407f6ce..f52262790d4b2 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1786,6 +1786,7 @@ def _get_default_index_names( def _get_names(self) -> tuple[Hashable | None, ...]: """ Retrieve the names associated with the object. + This method returns a tuple containing the name of the object. It's primarily intended for internal use. From 3380ce063d0f4c96fe37750c1ff24b24d20aab1d Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sat, 16 Mar 2024 16:50:04 +0100 Subject: [PATCH 22/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f52262790d4b2..220fc884f622f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1047,7 +1047,7 @@ def view(self, cls=None): See Also -------- - copy : Returns a copy of the Index. + Index.copy : Returns a copy of the Index. Examples -------- From f369d9538782522719d85f0b2613e46b490d29b6 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sat, 16 Mar 2024 16:50:13 +0100 Subject: [PATCH 23/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 220fc884f622f..70553ecffdcb3 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1795,6 +1795,11 @@ def _get_names(self) -> tuple[Hashable | None, ...]: tuple[Hashable | None, ...] A tuple containing the object's name, or None if the object does not have a name. + See Also + -------- + Index.name : Index name as a string instead of a tuple, or None for MultiIndex. + Series.name : Series name. + Examples -------- Create an index with a name and retrieve its names: From a7c5a95768c5d6c8461b786b7b6517d4acd06b26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 16 Mar 2024 22:32:03 +0000 Subject: [PATCH 24/29] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 70553ecffdcb3..2767110648cb4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1057,7 +1057,7 @@ def view(self, cls=None): Viewing as 'int32' reinterprets the memory, which may lead to unexpected behavior: - >>> idx.view('int32') + >>> idx.view("int32") array([1, 0, 2, 0, 3, 0], dtype=int32) """ # we need to see if we are subclassing an @@ -1804,7 +1804,7 @@ def _get_names(self) -> tuple[Hashable | None, ...]: -------- Create an index with a name and retrieve its names: - >>> index = pd.Index([1, 2, 3], name='example_name') + >>> index = pd.Index([1, 2, 3], name="example_name") >>> index.names ('example_name',) From e9c46eb5838f978ae9554157379482810dc90724 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 Mar 2024 00:34:36 +0100 Subject: [PATCH 25/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2767110648cb4..f9f95c6c01a51 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1034,7 +1034,8 @@ def view(self, cls=None): A view of the Index. If `cls` is None, the returned object is an Index view with the same dtype as the calling object. If a numeric `cls` is specified, the behavior depends on the compatibility of the conversion: - - If the conversion is valid, an ndarray view with the new dtype is returned. + - If the conversion is valid, an ndarray view with the new dtype is + returned. - If `cls` specifies a dtype that leads to an incompatible conversion, a ValueError is raised. From 937dc05ea64b1cd91f81242458626c08d6b0d9c2 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 Mar 2024 00:34:43 +0100 Subject: [PATCH 26/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f9f95c6c01a51..5445e8ae601a4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1056,7 +1056,8 @@ def view(self, cls=None): >>> idx.view() Index([1, 2, 3], dtype='int64') - Viewing as 'int32' reinterprets the memory, which may lead to unexpected behavior: + Viewing as 'int32' reinterprets the memory, which may lead to unexpected + behavior: >>> idx.view("int32") array([1, 0, 2, 0, 3, 0], dtype=int32) From 72ce2d8fa6e52edc4bcaab5f59005d798cb87853 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 Mar 2024 00:34:52 +0100 Subject: [PATCH 27/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5445e8ae601a4..97800e76825f0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1795,7 +1795,8 @@ def _get_names(self) -> tuple[Hashable | None, ...]: Returns ------- tuple[Hashable | None, ...] - A tuple containing the object's name, or None if the object does not have a name. + A tuple containing the object's name, or None if the object does not have a + name. See Also -------- From e39ee39c870c132c0a616d8f2c2bce11883d13cb Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 Mar 2024 01:08:22 +0100 Subject: [PATCH 28/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 97800e76825f0..a8f6a7327bf4d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1037,7 +1037,7 @@ def view(self, cls=None): - If the conversion is valid, an ndarray view with the new dtype is returned. - If `cls` specifies a dtype that leads to an incompatible conversion, - a ValueError is raised. + a ValueError is raised. Raises ------ From 358c804fa590732e49ec54dc91d7828968e6a591 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 Mar 2024 01:23:36 +0100 Subject: [PATCH 29/29] Update pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a8f6a7327bf4d..bbb2f1dc79506 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1033,11 +1033,7 @@ def view(self, cls=None): Index or ndarray A view of the Index. If `cls` is None, the returned object is an Index view with the same dtype as the calling object. If a numeric `cls` is - specified, the behavior depends on the compatibility of the conversion: - - If the conversion is valid, an ndarray view with the new dtype is - returned. - - If `cls` specifies a dtype that leads to an incompatible conversion, - a ValueError is raised. + specified an ndarray view with the new dtype is returned. Raises ------