From 858f4339f6acc066fa7582f57eef3c1a6110541c Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Sat, 24 Feb 2024 13:17:42 +0000 Subject: [PATCH 1/8] Added docstring for sheet_names --- pandas/io/excel/_base.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index cf9c3be97ee5c..cb1674a557209 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1629,6 +1629,29 @@ def book(self): @property def sheet_names(self): + """ + Returns a list of sheet names present in the document. + + This is mainly useful for loading a specific sheet into a dataframe when you do not + know the sheet names beforehand. + + Returns + ------- + list of str + List of sheet names in the document. + + See Also + -------- + ExcelFile.parse : Parse a sheet into a DataFrame. + read_excel : Read an Excel file into a pandas DataFrame. If you know the sheet + names, it may be easier to specify them directly to read_excel. + + Examples + -------- + >>> file = pd.ExcelFile("myfile.xlsx") + >>> file.sheet_names + ["Sheet1", "Sheet2"] + """ return self._reader.sheet_names def close(self) -> None: From 8857ca0b10d15709b1a44477d3477a66fea16334 Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Sat, 24 Feb 2024 13:57:25 +0000 Subject: [PATCH 2/8] Added docstring for codes --- pandas/core/indexes/multi.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index c59f756b4e146..f79c46d5b014e 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1078,6 +1078,27 @@ def levshape(self) -> Shape: @property def codes(self) -> tuple: + """ + Codes of the MultiIndex. + + Codes are the integer labels for each level designating which label at each location. + + Returns + ------- + tuple of (numpy.ndarray,) + The codes of the MultiIndex. Each array in the tuple corresponds to a level in the MultiIndex. + + See Also + -------- + MultiIndex.set_codes : Set new codes on MultiIndex. + + Examples + -------- + >>> arrays = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]] + >>> mi = pd.MultiIndex.from_arrays(arrays, names=("number", "color")) + >>> mi.codes + (array([0, 0, 1, 1], dtype=int8), array([1, 0, 1, 0], dtype=int8)) + """ return self._codes def _set_codes( From 8aa4e54705f9620aab5e086e655cae2bb5144f7a Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Sat, 24 Feb 2024 13:57:42 +0000 Subject: [PATCH 3/8] Updated sheet_names docstring --- pandas/io/excel/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index cb1674a557209..257bcfdcac26c 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1630,7 +1630,7 @@ def book(self): @property def sheet_names(self): """ - Returns a list of sheet names present in the document. + Names of the sheets in the document. This is mainly useful for loading a specific sheet into a dataframe when you do not know the sheet names beforehand. From 62fe5497feb93bfa540f6b945bb3b7096596ed7b Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Sat, 24 Feb 2024 13:59:13 +0000 Subject: [PATCH 4/8] Removed methods from code_checks.sh --- ci/code_checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f1e7f6d477906..94ba0fe55e40c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -146,7 +146,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DatetimeIndex.as_unit\ pandas.DatetimeIndex.freq\ pandas.ExcelFile.book\ - pandas.ExcelFile.sheet_names\ pandas.Index.empty\ pandas.Index.names\ pandas.Index.view\ @@ -154,7 +153,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.IntervalIndex.length\ pandas.IntervalIndex.mid\ pandas.IntervalIndex.right\ - pandas.MultiIndex.codes\ pandas.Period.freq\ pandas.Period.ordinal\ pandas.PeriodIndex.freq\ From fa0644499b89833dba16b171d465f096d8e8d63e Mon Sep 17 00:00:00 2001 From: thomasdamcevski <97948306+thomasdamcevski@users.noreply.github.com> Date: Sun, 25 Feb 2024 11:13:33 +1100 Subject: [PATCH 5/8] Update sheet_names docstring Co-authored-by: Jonas Bergner <44500888+bergnerjonas@users.noreply.github.com> --- pandas/io/excel/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 257bcfdcac26c..a7026dc8c7db0 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1632,7 +1632,7 @@ def sheet_names(self): """ Names of the sheets in the document. - This is mainly useful for loading a specific sheet into a dataframe when you do not + This is mainly useful for loading a specific sheet into a DataFrame when you do not know the sheet names beforehand. Returns From b1c153c652707d9f81a8cd01d0487eda8764ca42 Mon Sep 17 00:00:00 2001 From: thomasdamcevski <97948306+thomasdamcevski@users.noreply.github.com> Date: Sun, 25 Feb 2024 11:15:06 +1100 Subject: [PATCH 6/8] Update MultiIndex.codes docstring to be less awkward Co-authored-by: Jonas Bergner <44500888+bergnerjonas@users.noreply.github.com> --- pandas/core/indexes/multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index f79c46d5b014e..e1a84e9f207e6 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1081,7 +1081,7 @@ def codes(self) -> tuple: """ Codes of the MultiIndex. - Codes are the integer labels for each level designating which label at each location. + Codes are the integer labels for each level designating the position of the index value in a sorted list of all index values in that level. Returns ------- From eae6a2da8c08dccc592dcf732ba47054ac6132c9 Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Sun, 25 Feb 2024 12:16:50 +0000 Subject: [PATCH 7/8] Fixed failing doctest --- pandas/io/excel/_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index a7026dc8c7db0..2c916b129edd0 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1632,8 +1632,8 @@ def sheet_names(self): """ Names of the sheets in the document. - This is mainly useful for loading a specific sheet into a DataFrame when you do not - know the sheet names beforehand. + This is mainly useful for loading a specific sheet into a DataFrame when + you do not know the sheet names beforehand. Returns ------- @@ -1648,8 +1648,8 @@ def sheet_names(self): Examples -------- - >>> file = pd.ExcelFile("myfile.xlsx") - >>> file.sheet_names + >>> file = pd.ExcelFile("myfile.xlsx") # doctest: +SKIP + >>> file.sheet_names # doctest: +SKIP ["Sheet1", "Sheet2"] """ return self._reader.sheet_names From 08f9c043f55c99864fff1a44ca4d031899eb7fca Mon Sep 17 00:00:00 2001 From: thomasdamcevski Date: Tue, 27 Feb 2024 08:11:37 +0000 Subject: [PATCH 8/8] Applied suggestions --- pandas/core/indexes/multi.py | 8 +++++--- pandas/io/excel/_base.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index e1a84e9f207e6..119c86770af3e 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1081,12 +1081,14 @@ def codes(self) -> tuple: """ Codes of the MultiIndex. - Codes are the integer labels for each level designating the position of the index value in a sorted list of all index values in that level. + Codes are the position of the index value in the list of level values + for each level. Returns ------- - tuple of (numpy.ndarray,) - The codes of the MultiIndex. Each array in the tuple corresponds to a level in the MultiIndex. + tuple of numpy.ndarray + The codes of the MultiIndex. Each array in the tuple corresponds + to a level in the MultiIndex. See Also -------- diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 2c916b129edd0..894ffbe5d5aa7 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1632,7 +1632,7 @@ def sheet_names(self): """ Names of the sheets in the document. - This is mainly useful for loading a specific sheet into a DataFrame when + This is particularly useful for loading a specific sheet into a DataFrame when you do not know the sheet names beforehand. Returns