make sheet_id optional
This commit is contained in:
parent
3acc0d977b
commit
f2134b4822
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue