Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Fixing GL08 errors for pandas.ExcelFile.sheet_names and pandas.MultiIndex.codes #57601

Merged
merged 11 commits into from
Feb 27, 2024
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
MSG='Partially validate docstrings (GL08)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL08 --ignore_functions \
pandas.ExcelFile.book\
pandas.ExcelFile.sheet_names\
pandas.Index.empty\
pandas.Index.names\
pandas.Index.view\
pandas.IntervalIndex.left\
pandas.IntervalIndex.length\
pandas.IntervalIndex.mid\
pandas.IntervalIndex.right\
pandas.MultiIndex.codes\
pandas.Period.freq\
pandas.Period.ordinal\
pandas.PeriodIndex.freq\
Expand Down
23 changes: 23 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,29 @@ def levshape(self) -> Shape:

@property
def codes(self) -> tuple:
"""
Codes of the MultiIndex.

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.

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(
Expand Down
23 changes: 23 additions & 0 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,29 @@ def book(self):

@property
def sheet_names(self):
"""
Names of the sheets in the document.

This is particularly 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") # doctest: +SKIP
>>> file.sheet_names # doctest: +SKIP
["Sheet1", "Sheet2"]
"""
return self._reader.sheet_names

def close(self) -> None:
Expand Down