-
Notifications
You must be signed in to change notification settings - Fork 36
added stream support to from_btl for issue #142 #146
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
Changes from all commits
a97227f
8fce656
7c21aa9
87e64fc
d1b617e
180f761
b538acb
ea03856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,10 @@ def btl(): | |
|
|
||
|
|
||
| @pytest.fixture | ||
| def btl_duplicate_header_name(): | ||
| yield ctd.from_btl(data_path.joinpath("btl", "alt_bottletest.BTL")) | ||
| def btl_as_stream(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not need to be a fixture b/c we won't be calling it multiple times in tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm not use to unittesting specifically with pytest I was just emulating what other tests had done, I'll fix it up.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't worry and no need to be sorry. The only reason I'm not sending commit directly to your branch is b/c I believe you want to do this. If not, I can take over. Your contributions and very welcomed and I'm trying to pay back by showing a bit how my messy tests work. |
||
| file = open(mode="rb", file=data_path.joinpath("btl", "alt_bottletest.BTL")) | ||
| stream = StringIO(file.read().decode("cp1252")) | ||
| yield ctd.from_btl(stream) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -83,10 +85,13 @@ def test_btl_is_dataframe(btl): | |
| assert not btl.empty | ||
|
|
||
|
|
||
| def test_btl_with_dup_cols(btl_duplicate_header_name): | ||
| assert all( | ||
| col in btl_duplicate_header_name.columns for col in ["Bottle", "Bottle_"] | ||
| ) | ||
| def test_btl_with_dup_cols(btl_as_stream): | ||
| assert all(col in btl_as_stream.columns for col in ["Bottle", "Bottle_"]) | ||
|
|
||
|
|
||
| def test_btl_as_stringio(btl_as_stream): | ||
| assert isinstance(btl_as_stream, pd.DataFrame) | ||
| assert not btl_as_stream.empty | ||
|
|
||
|
|
||
| def test_ros_is_dataframe(ros): | ||
|
|
||
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.
This Forces folks using stream to always pass a name but that is optional, so the API here is kind of broken. (At least lacking documentation.)
Ideally we should check if it is stream and hardcode a default name for those cases.
For that to work we should move this check to
_read_fileand make it output bothfandnamethere. That way we check for StringIO only once.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.
I hope I'm not over complicating this idea, but did you want
_read_fileto return a tuple of values, the first being the StringIO object and the second being the file/stream name?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.
Yes.
_read_fileis an internal use function, so it is OK to "break it" and better than changing the call onfrom_btl. Does that make sense?Uh oh!
There was an error while loading. Please reload this page.
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.
Here's an idea.
What if when reading the file, we grab the BTL "File Name" in the header section and use that to set the file name?
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.
We need to check if that metadata exists and, if not, fill with a placeholder. But sure, that is probably the best way to go.
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.
Sorry, what I mean is what if we got the file name in the _parse_seabird() method, if a name hasn't been set already.