Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes several bugs in reader_dispatch #108

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
17 changes: 13 additions & 4 deletions thicket/thicket.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,32 @@ def reader_dispatch(func, intersection=False, *args, **kwargs):
"""
ens_list = []
obj = args[0] # First arg should be readable object
extra_args = []
if len(args) > 1:
extra_args = args[1:]

# Parse the input object
# if a list of files
if type(obj) == list:
if isinstance(obj, (list, tuple)):
for file in obj:
ens_list.append(Thicket.thicketize_graphframe(func(file), file))
ens_list.append(
Thicket.thicketize_graphframe(
func(file, *extra_args, **kwargs), file
)
)
# if directory of files
elif os.path.isdir(obj):
for file in os.listdir(obj):
f = os.path.join(obj, file)
ens_list.append(Thicket.thicketize_graphframe(func(f), f))
ens_list.append(
Thicket.thicketize_graphframe(func(f, *extra_args, **kwargs), f)
)
# if single file
elif os.path.isfile(obj):
return Thicket.thicketize_graphframe(func(*args, **kwargs), args[0])
# Error checking
else:
if type(obj) == str and not os.path.isfile(obj):
if isinstance(obj, str) and not os.path.isfile(obj):
raise FileNotFoundError("File '" + obj + "' not found.")
else:
raise TypeError(
Expand Down
Loading