-
Notifications
You must be signed in to change notification settings - Fork 2
chore: Add regression tests for DataFrame rendering and analysis #25
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
m1so
wants to merge
4
commits into
main
Choose a base branch
from
michalbaumgartner/blu-5140-trino-rendering-is-broken-for-structs
base: main
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d011e7b
fix(trino): convert STRUCT/ROW/ARRAY types to valid JSON strings
m1so 6f4b085
fix: imports due to Trino update (0.327.0 -> 0.330.0)
m1so 08f83d0
Merge branch 'main' into michalbaumgartner/blu-5140-trino-rendering-i…
m1so 4b40a57
chore: Add regression tests for DataFrame rendering and analysis
m1so 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
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| from deepnote_toolkit.ocelots.pandas.utils import safe_convert_to_string | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_dict(): | ||
| dict_value = {"a": "x", "b": "y"} | ||
| result = safe_convert_to_string(dict_value) | ||
|
|
||
| assert isinstance(result, str) | ||
| parsed = json.loads(result) | ||
| assert parsed == dict_value | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_tuple(): | ||
| tuple_value = (1, "x", True) | ||
| result = safe_convert_to_string(tuple_value) | ||
|
|
||
| assert isinstance(result, str) | ||
| parsed = json.loads(result) | ||
| assert parsed == [1, "x", True] | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_list(): | ||
| list_value = ["a", "b", "c"] | ||
| result = safe_convert_to_string(list_value) | ||
|
|
||
| assert isinstance(result, str) | ||
| parsed = json.loads(result) | ||
| assert parsed == list_value | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_nested_structures(): | ||
| nested_value = {"key": "value", "nested": {"inner": [1, 2, 3]}} | ||
| result = safe_convert_to_string(nested_value) | ||
|
|
||
| parsed = json.loads(result) | ||
| assert parsed == nested_value | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_regular_values(): | ||
| assert safe_convert_to_string("hello") == "hello" | ||
|
|
||
| assert safe_convert_to_string(42) == "42" | ||
| assert safe_convert_to_string(3.14) == "3.14" | ||
|
|
||
| assert safe_convert_to_string(True) == "True" | ||
|
|
||
| assert safe_convert_to_string(None) == "None" | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_unconvertible(): | ||
|
|
||
| class UnconvertibleObject: | ||
| def __str__(self): | ||
| raise ValueError("Cannot convert") | ||
|
|
||
| def __repr__(self): | ||
| raise ValueError("Cannot represent") | ||
|
|
||
| result = safe_convert_to_string(UnconvertibleObject()) | ||
| assert result == "<unconvertible>" | ||
|
|
||
|
|
||
| # Tests for Trino-specific types | ||
| def test_safe_convert_to_string_trino_namedrowtuple(): | ||
| """Test that Trino's NamedRowTuple is converted to valid JSON strings.""" | ||
| pytest.importorskip("trino.types") | ||
| from trino.types import NamedRowTuple | ||
|
|
||
| # Create a NamedRowTuple with field names and values (as returned by Trino) | ||
| row = NamedRowTuple( | ||
| values=["item_1", "value_10"], names=["a", "b"], types=[None, None] | ||
| ) | ||
|
|
||
| result = safe_convert_to_string(row) | ||
|
|
||
| assert isinstance(result, str) | ||
| parsed = json.loads(result) | ||
| assert parsed == ["item_1", "value_10"] | ||
| assert row.a == "item_1" | ||
| assert row.b == "value_10" | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_trino_array(): | ||
| """Test that Trino arrays (returned as Python lists) are converted to valid JSON.""" | ||
|
|
||
| # Trino returns ARRAY types as Python lists | ||
| trino_array = ["tag_1", "item", "test"] | ||
|
|
||
| result = safe_convert_to_string(trino_array) | ||
|
|
||
| assert isinstance(result, str) | ||
|
|
||
| parsed = json.loads(result) | ||
| assert parsed == trino_array | ||
| assert '"tag_1"' in result | ||
| assert "'tag_1'" not in result | ||
|
|
||
|
|
||
| def test_safe_convert_to_string_trino_nested_array(): | ||
| """Test that nested Trino arrays are converted to valid JSON.""" | ||
|
|
||
| # Trino returns nested ARRAY types as nested Python lists | ||
| nested_array = [[1, 2], [3, 4]] | ||
|
|
||
| result = safe_convert_to_string(nested_array) | ||
|
|
||
| parsed = json.loads(result) | ||
| assert parsed == nested_array | ||
| assert parsed[0] == [1, 2] | ||
| assert parsed[1] == [3, 4] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.