From f2134b4822ad26794f853d1a7d5b911b4da7bd52 Mon Sep 17 00:00:00 2001 From: iuvbio Date: Sun, 23 Feb 2020 17:17:25 +0100 Subject: [PATCH] make sheet_id optional --- README.md | 3 +++ pandas_ods_reader/parser.py | 4 ++-- tests/test_read_ods.py | 11 ++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8a19bcb..ea0add7 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ from pandas_ods_reader import read_ods path = "path/to/file.ods" +# by default the first sheet is imported +df = pd.read_ods(path) + # load a sheet based on its index (1 based) sheet_idx = 1 df = read_ods(path, sheet_idx) diff --git a/pandas_ods_reader/parser.py b/pandas_ods_reader/parser.py index b002fe6..2f9d2e2 100644 --- a/pandas_ods_reader/parser.py +++ b/pandas_ods_reader/parser.py @@ -59,7 +59,7 @@ def load_ods(doc, sheet_id, headers=True, columns=None): return df -def read_ods(file_or_path, sheet, headers=True, columns=None): +def read_ods(file_or_path, sheet=1, headers=True, columns=None): """ This function reads in the provided ods file and converts it to a dictionary. The dictionary is converted to a DataFrame. Trailing empty rows @@ -67,7 +67,7 @@ def read_ods(file_or_path, sheet, headers=True, columns=None): :param file_or_path: str the path to the ODS file - :param sheet: int or str + :param sheet: int or str, default 1 if int, the 1 based index of the sheet to be read in. If str, the name of the sheet to be read in :param header: bool, default True diff --git a/tests/test_read_ods.py b/tests/test_read_ods.py index c551bb5..f99d283 100644 --- a/tests/test_read_ods.py +++ b/tests/test_read_ods.py @@ -18,7 +18,16 @@ missing_header_file = "example_missing_header.ods" mixed_dtypes_file = "mixed_dtypes.ods" -class TestOdsReader(object): +class TestOdsReader: + + def test_header_file_simple(self): + + path = rsc / header_file + df = read_ods(path) + + assert isinstance(df, pd.DataFrame) + assert len(df) == 10 + assert (len(df.columns) == 5) def test_header_file_with_int(self):