-
Notifications
You must be signed in to change notification settings - Fork 12
fix(rnd-21448): Fixtures.to_df() returns empty values for nested vessel/corporate_entities fields #571
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
Open
hansenfan
wants to merge
6
commits into
master
Choose a base branch
from
rnd-21448
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
fix(rnd-21448): Fixtures.to_df() returns empty values for nested vessel/corporate_entities fields #571
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a00fa24
fix: populating fixtures data
hansenfan 1928359
fix: aligned with pr conventions
hansenfan 296f93b
fix: fixed docstring
hansenfan 7ce8889
fix: updated documentation
hansenfan f6d5428
fix: deployment formatting
hansenfan fcb4e07
fix: safety against empty corporate entities
hansenfan 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from vortexasdk.api.entity_flattening import ( | ||
| convert_to_flat_dict, | ||
| convert_fixture_to_flat_dict, | ||
| ) | ||
|
|
||
|
|
||
| class TestFixtureFlattening(TestCase): | ||
| """Test that convert_fixture_to_flat_dict groups corporate_entities by layer.""" | ||
|
|
||
| FIXTURE = { | ||
| "id": "abc123", | ||
| "vessel": { | ||
| "id": "v1", | ||
| "name": "ALPINE EAGLE", | ||
| "imo": 9480980, | ||
| "mmsi": 255804460, | ||
| "dwt": 300000, | ||
| "cubic_capacity": 330000, | ||
| "vessel_class": "vlcc", | ||
| "classes": [], | ||
| "corporate_entities": [ | ||
| { | ||
| "id": "ec1", | ||
| "layer": "effective_controller", | ||
| "label": "Frontline Ltd", | ||
| "probability": 1, | ||
| "source": "external", | ||
| }, | ||
| { | ||
| "id": "tc1", | ||
| "layer": "time_charterer", | ||
| "label": "Shell", | ||
| "probability": 0.8, | ||
| "source": "model", | ||
| "start_timestamp": "2023-06-01", | ||
| "end_timestamp": "2024-06-01", | ||
| }, | ||
| ], | ||
| "tags": [], | ||
| "flag": [], | ||
| "scrubber": [], | ||
| }, | ||
| "tonnes": 270000, | ||
| "laycan_from": "2024-01-01T00:00:00+0000", | ||
| "laycan_to": "2024-01-03T00:00:00+0000", | ||
| "fixing_timestamp": "2023-12-28T14:30:00+0000", | ||
| "vtx_fulfilled": True, | ||
| "origin": {"id": "org1", "label": "Arabian Gulf"}, | ||
| "destination": {"id": "dst1", "label": "South Korea"}, | ||
| "product": {"id": "prd1", "label": "Crude"}, | ||
| "charterer": {"id": "c1", "label": "Trafigura"}, | ||
| } | ||
|
|
||
| def test_generic_flattener_uses_numeric_indices(self): | ||
| flat = convert_to_flat_dict(self.FIXTURE, columns="all") | ||
| assert "vessel.corporate_entities.0.label" in flat | ||
| assert ( | ||
| "vessel.corporate_entities.effective_controller.label" not in flat | ||
| ) | ||
|
|
||
| def test_fixture_flattener_groups_by_layer(self): | ||
| flat = convert_fixture_to_flat_dict(self.FIXTURE, columns="all") | ||
| assert ( | ||
| flat["vessel.corporate_entities.effective_controller.label"] | ||
| == "Frontline Ltd" | ||
| ) | ||
| assert ( | ||
| flat["vessel.corporate_entities.time_charterer.label"] == "Shell" | ||
| ) | ||
|
|
||
| def test_fixture_flattener_preserves_flat_fields(self): | ||
| flat = convert_fixture_to_flat_dict(self.FIXTURE, columns="all") | ||
| assert flat["vessel.name"] == "ALPINE EAGLE" | ||
| assert flat["vessel.imo"] == 9480980 | ||
| assert flat["tonnes"] == 270000 | ||
| assert flat["charterer.label"] == "Trafigura" | ||
|
|
||
| def test_fixture_flattener_column_filter(self): | ||
| cols = [ | ||
| "vessel.name", | ||
| "vessel.corporate_entities.effective_controller.label", | ||
| ] | ||
| flat = convert_fixture_to_flat_dict(self.FIXTURE, columns=cols) | ||
| assert set(flat.keys()) == set(cols) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "1.0.29" | ||
| __version__ = "1.0.30a1" |
Oops, something went wrong.
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.
Would appreciate some input on this. I think because changing to tonnes could be a breaking change it is doing this to make sure that people don't have to modify anything but idk if that's a good practice