-
Notifications
You must be signed in to change notification settings - Fork 5
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
Updates to read CSV method #1512
Open
mnjowe
wants to merge
16
commits into
master
Choose a base branch
from
mnjowe/updates_to_read_csv_files_method_in_utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7352c14
update read csv method to accept datatypes and allow return a diction…
mnjowe 4f96c65
update read csv files method return statement
mnjowe 8c61da4
remove unnecessary print statement
mnjowe 375cf75
Merge branch 'master' into mnjowe/updates_to_read_csv_files_method_in…
mnjowe 43e8499
update test to directly use tmpdir
mnjowe 4506ae5
update read csv files method. add capability to pass a string, update…
mnjowe 7055d15
update method, set flag to determine return type
mnjowe 8da1c07
update test, return dataframe instead of a dictionary
mnjowe 5dec218
Merge branch 'master' into mnjowe/updates_to_read_csv_files_method_in…
mnjowe c95a206
Merge remote-tracking branch 'origin/mnjowe/updates_to_read_csv_files…
mnjowe ce79832
Merge branch 'master' into mnjowe/updates_to_read_csv_files_method_in…
mnjowe 42421ae
update comment
mnjowe d505cfb
use glob instead of rglob as we are only focusing on the current dire…
mnjowe d6623c5
Merge branch 'master' into mnjowe/updates_to_read_csv_files_method_in…
mnjowe 9a930d5
add a condition to deny unexpected files
mnjowe d8ef8f6
set return_dict flag first
mnjowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment this
else
clause will be run wheneverfiles
is not a instancelist
orstr
and is notNone
. Looking at the type hint / default value I guess this is meant to cover the case whenfiles
is an instance of anint
? If so it would be better to make thiselif isinstance(files, int):
and add a separateelse:
clause that raises an error sayingfiles
is not of an expected type if none of the previous clauses have run. At the moment for example if a user passes a non-list iterable data structure as thefiles
argument - for example a tuple or generator (as returned for example byPath.glob
andPath.rglob
) then the value passed will be silently overwritten which is probably not what they would expect. Failing loudly iffiles
is of an unexpected type (and/or allowingfiles
to be of more general iterable types by for example checking if it is an instance ofIterable
fromcollections.abc
instead oflist
) would be better here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also avoid the duplication of the list comprehension
[f_name.stem for f_name in folder.glob("*.csv")]
by having something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thought of combining those two conditions crossed my mind but I was lacking the smart way of setting
return_dict
to either True or False. thanks for this @matt-grahamThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe using
isinstance(files, collections.abc.Iterable)
is not the best approach here, as it also considers strings to be iterable. If a string is included, it could alter the expected behavior of the return type when modelers specify a file name by passing a string. This would cause the method to return a dictionary instead of a DataFrame, which is likely not the intended outcome.