Skip to content

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

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

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 @@ -146,15 +146,13 @@ 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\
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
21 changes: 21 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@ -1629,6 +1629,29 @@ def book(self):

@property
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.

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:
Expand Down