Skip to content

Commit 5ec999e

Browse files
committed
Finally cleaning up
1 parent 748d90f commit 5ec999e

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ including other versions of pandas.
1111
.. ---------------------------------------------------------------------------
1212
.. _whatsnew_300.enhancements:
1313

14-
15-
1614
Enhancements
1715
~~~~~~~~~~~~
16+
1817
.. _whatsnew_300.enhancements.read_excel_table_parameter:
1918

2019
``Addition of table name parameter in pandas read_excel``
21-
^^^^^^^^^^^^^^^^
20+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2221

2322
Previously, when using pandas :func:`read_excel`` method the data read from Excel could not be selected in more detail than on the sheet level.
2423
To distinguish data that is part of a particular table in the Excel file could be tedious without the use of third party API's.
@@ -31,6 +30,7 @@ holding the data from each sheet.
3130
- If a table_name is specified and a sheet_name is also specified, the return with be a nested dictionary containing 2 dictionaries:
3231
- The first dictionary is a dictionary of DataFrames corresponding to the data on each sheet
3332
- The second dictionary is a dictionary of DataFrames corresponding to the data in each table
33+
3434
.. _whatsnew_300.enhancements.enhancement1:
3535

3636
enhancement1

pandas/io/excel/_base.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
HashableT,
8181
IntStrT,
8282
ReadBuffer,
83-
Scalar,
8483
Self,
8584
SequenceNotStr,
8685
StorageOptions,
@@ -431,7 +430,7 @@ def read_excel(
431430
skipfooter: int = ...,
432431
storage_options: StorageOptions = ...,
433432
dtype_backend: DtypeBackend | lib.NoDefault = ...,
434-
) -> DataFrame | list[DataFrame] | dict[str, DataFrame]: ...
433+
) -> DataFrame | dict[str, DataFrame] | dict[str, dict[str, DataFrame]]: ...
435434

436435

437436
@overload
@@ -472,7 +471,12 @@ def read_excel(
472471
skipfooter: int = ...,
473472
storage_options: StorageOptions = ...,
474473
dtype_backend: DtypeBackend | lib.NoDefault = ...,
475-
) -> DataFrame | dict[IntStrT, DataFrame] | dict[str, DataFrame]: ...
474+
) -> (
475+
DataFrame
476+
| dict[IntStrT, DataFrame]
477+
| dict[str, DataFrame]
478+
| dict[str, dict[str, DataFrame]]
479+
): ...
476480

477481

478482
@doc(storage_options=_shared_docs["storage_options"])
@@ -513,7 +517,12 @@ def read_excel(
513517
storage_options: StorageOptions | None = None,
514518
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
515519
engine_kwargs: dict | None = None,
516-
) -> DataFrame | list[DataFrame] | dict[str, DataFrame]:
520+
) -> (
521+
DataFrame
522+
| dict[IntStrT, DataFrame]
523+
| dict[str, DataFrame]
524+
| dict[str, dict[str, DataFrame]]
525+
):
517526
check_dtype_backend(dtype_backend)
518527
should_close = False
519528
if engine_kwargs is None:
@@ -806,6 +815,7 @@ def parse(
806815
# handle same-type duplicates.
807816
sheets = cast(Union[list[int], list[str]], list(dict.fromkeys(sheets).keys()))
808817

818+
output: dict[str, DataFrame] | dict[str, dict[str, DataFrame]]
809819
output = {"sheets": {}, "tables": {}}
810820
outputDict = None
811821

@@ -832,7 +842,7 @@ def parse(
832842
output[outputDict][asheetname] = DataFrame()
833843
continue
834844

835-
output = self.parse_multiindex(
845+
output = self.parse_data(
836846
data=data,
837847
asheetname=asheetname,
838848
header=header,
@@ -889,7 +899,7 @@ def parse(
889899
output[outputDict][atablename] = DataFrame()
890900
continue
891901

892-
output = self.parse_multiindex(
902+
output = self.parse_data(
893903
data=table_data,
894904
asheetname=atablename,
895905
header=header,
@@ -932,12 +942,12 @@ def parse(
932942
else:
933943
return output["sheets"][last_sheetname]
934944

935-
def parse_multiindex(
945+
def parse_data(
936946
self,
937-
data: list[list[Scalar]] | None = None,
947+
data: list,
948+
output: dict,
938949
asheetname: str | int | None = None,
939950
header: int | Sequence[int] | None = 0,
940-
output: dict | None = None,
941951
outputDict: str | None = None,
942952
names: SequenceNotStr[Hashable] | range | None = None,
943953
index_col: int | Sequence[int] | None = None,

0 commit comments

Comments
 (0)