Skip to content

Commit f40172e

Browse files
thomasdamcevskibergnerjonas
authored andcommitted
DOC: Fixing GL08 errors for pandas.ExcelFile.sheet_names and pandas.MultiIndex.codes (pandas-dev#57601)
Co-authored-by: Jonas Bergner <[email protected]>
1 parent abe41e6 commit f40172e

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

ci/code_checks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,13 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
145145
MSG='Partially validate docstrings (GL08)' ; echo $MSG
146146
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL08 --ignore_functions \
147147
pandas.ExcelFile.book\
148-
pandas.ExcelFile.sheet_names\
149148
pandas.Index.empty\
150149
pandas.Index.names\
151150
pandas.Index.view\
152151
pandas.IntervalIndex.left\
153152
pandas.IntervalIndex.length\
154153
pandas.IntervalIndex.mid\
155154
pandas.IntervalIndex.right\
156-
pandas.MultiIndex.codes\
157155
pandas.Period.freq\
158156
pandas.Period.ordinal\
159157
pandas.PeriodIndex.freq\

pandas/core/indexes/multi.py

+23
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,29 @@ def levshape(self) -> Shape:
10781078

10791079
@property
10801080
def codes(self) -> tuple:
1081+
"""
1082+
Codes of the MultiIndex.
1083+
1084+
Codes are the position of the index value in the list of level values
1085+
for each level.
1086+
1087+
Returns
1088+
-------
1089+
tuple of numpy.ndarray
1090+
The codes of the MultiIndex. Each array in the tuple corresponds
1091+
to a level in the MultiIndex.
1092+
1093+
See Also
1094+
--------
1095+
MultiIndex.set_codes : Set new codes on MultiIndex.
1096+
1097+
Examples
1098+
--------
1099+
>>> arrays = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]]
1100+
>>> mi = pd.MultiIndex.from_arrays(arrays, names=("number", "color"))
1101+
>>> mi.codes
1102+
(array([0, 0, 1, 1], dtype=int8), array([1, 0, 1, 0], dtype=int8))
1103+
"""
10811104
return self._codes
10821105

10831106
def _set_codes(

pandas/io/excel/_base.py

+23
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,29 @@ def book(self):
16301630

16311631
@property
16321632
def sheet_names(self):
1633+
"""
1634+
Names of the sheets in the document.
1635+
1636+
This is particularly useful for loading a specific sheet into a DataFrame when
1637+
you do not know the sheet names beforehand.
1638+
1639+
Returns
1640+
-------
1641+
list of str
1642+
List of sheet names in the document.
1643+
1644+
See Also
1645+
--------
1646+
ExcelFile.parse : Parse a sheet into a DataFrame.
1647+
read_excel : Read an Excel file into a pandas DataFrame. If you know the sheet
1648+
names, it may be easier to specify them directly to read_excel.
1649+
1650+
Examples
1651+
--------
1652+
>>> file = pd.ExcelFile("myfile.xlsx") # doctest: +SKIP
1653+
>>> file.sheet_names # doctest: +SKIP
1654+
["Sheet1", "Sheet2"]
1655+
"""
16331656
return self._reader.sheet_names
16341657

16351658
def close(self) -> None:

0 commit comments

Comments
 (0)