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
23 changes: 21 additions & 2 deletions example_pipeline/data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,34 @@ def check_dataframe(df, columns, column_to_dtype=None):

def _handle_file_path(func):
def func_wrapper(file_path, *args, **kwargs):
pathlib_object = _get_pathlib_object(file_path)
pathlib_object = _sanitize_file_path(file_path)
output = func(pathlib_object, *args, **kwargs)
return output
func_wrapper.__name__ = func.__name__
func_wrapper.__doc__ = func.__doc__
return func_wrapper


def _get_pathlib_object(file_path):
def _sanitize_file_path(file_path):
""""
Converts given filepath to correct os-dependent file path.
Checks to see if filepath exists, if not, checks that parent exists for
writing
"""
# convert to filepath
pathlib_filepath = pathlib.Path(file_path)

# check file exists
if pathlib_filepath.isfile():
pass
elif pathlib_filepath.parent.isdir():
pass
else:
raise Exception("Filepath is incorrect")

# convert to os-dependent string
file_path = str(pathlib_filepath)

return file_path


Expand Down