Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions dskit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,8 @@ def load(filepath):

def read_folder(folder_path:str, file_type:str='csv',dynamic:bool=False,display_ignored:bool=False):
"""
Load and concatenate tabular files from a folder.
Parameters
----------
folder_path : str
Path to the directory containing the files to be loaded.

file_type : str, default='csv'
File extension to filter files when `dynamic=False`.
Example: 'csv', 'xlsx', 'parquet'.

dynamic : bool, default=False
If True, loads all files regardless of extension.
If False, only files matching `file_type` are loaded.

display_ignored : bool, default=False
If True, prints the list of files that were skipped
because they could not be loaded by the `load()` function.
Load multiple files from a folder and return
a list of pandas DataFrames.
"""
if not os.path.exists(folder_path):
raise FileNotFoundError(f"The folder '{folder_path}' was not found.")
Expand All @@ -71,7 +56,7 @@ def read_folder(folder_path:str, file_type:str='csv',dynamic:bool=False,display_
if display_ignored:
print("Ignored Files : ","\n".join(ignored))
if df_list:
return pd.concat(df_list, ignore_index=True)
return df_list
else:
return None

Expand Down