From 96b8fe11da8fdeaf83cd3608f80d86b993d67212 Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Thu, 17 Oct 2024 11:39:33 +0200 Subject: [PATCH] Update type of usecols in _read_excel usecols takes str, list-like or callable Update outdated docstring. --- src/ert/config/design_matrix.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ert/config/design_matrix.py b/src/ert/config/design_matrix.py index 1683463568e..fd8f262e9ef 100644 --- a/src/ert/config/design_matrix.py +++ b/src/ert/config/design_matrix.py @@ -149,26 +149,24 @@ def read_design_matrix( def _read_excel( file_name: Union[Path, str], sheet_name: str, - usecols: Optional[Union[int, List[int]]] = None, + usecols: Optional[List[int]] = None, header: Optional[int] = 0, skiprows: Optional[int] = None, dtype: Optional[str] = None, ) -> pd.DataFrame: """ - Make dataframe from excel file - :return: Dataframe - :raises: OsError if file not found - :raises: ValueError if file not loaded correctly + Reads an Excel file into a DataFrame, with options to filter columns and rows, + and automatically drops columns that contain only NaN values. """ - dframe: pd.DataFrame = pd.read_excel( - file_name, - sheet_name, + df = pd.read_excel( + io=file_name, + sheet_name=sheet_name, usecols=usecols, header=header, skiprows=skiprows, dtype=dtype, ) - return dframe.dropna(axis=1, how="all") + return df.dropna(axis=1, how="all") @staticmethod def _validate_design_matrix(design_matrix: pd.DataFrame) -> List[str]: