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 input dict display in UI #1254

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
29 changes: 21 additions & 8 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def fn() -> int:
assert node_copy_copy.name == "rename_fn_again"


np_version = np.__version__
major, minor, _ = map(int, np_version.split("."))


@pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python 3.9 or higher")
def test_node_handles_annotated():
from typing import Annotated
Expand All @@ -56,15 +60,24 @@ def annotated_func(first: ArrayN[np.float64], other: float = 2.0) -> ArrayN[np.f

node = Node.from_fn(annotated_func)
assert node.name == "annotated_func"
expected = {
"first": (
Annotated[np.ndarray[Any, np.dtype[np.float64]], Literal["N"]],
DependencyType.REQUIRED,
),
"other": (float, DependencyType.OPTIONAL),
}
if major == 2 and minor > 1: # greater that 2.1
expected = {
"first": (
Annotated[np.ndarray[tuple[int, ...], np.dtype[np.float64]], Literal["N"]],
DependencyType.REQUIRED,
),
"other": (float, DependencyType.OPTIONAL),
}
else:
expected = {
"first": (
Annotated[np.ndarray[Any, np.dtype[np.float64]], Literal["N"]],
DependencyType.REQUIRED,
),
"other": (float, DependencyType.OPTIONAL),
}
assert node.input_types == expected
assert node.type == Annotated[np.ndarray[Any, np.dtype[np.float64]], Literal["N"]]
assert node.type == Annotated[np.ndarray[tuple[int, ...], np.dtype[np.float64]], Literal["N"]]


@pytest.mark.parametrize(
Expand Down
9 changes: 8 additions & 1 deletion ui/frontend/src/components/dashboard/Runs/Run/Run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ const VariableTable = (props: {
<code>{variableKey}</code>
</td>
{values.map((value, i) => {
let json_string = "";
if (value) {
json_string = JSON.stringify(value, null, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if the value is already a string before using JSON.stringify to avoid unnecessary quotes around string values.

Suggested change
json_string = JSON.stringify(value, null, 2);
json_string = typeof value === 'string' ? value : JSON.stringify(value, null, 2);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to do this unless you want strings to show up as not quoted (which is odd, the type is a string so a quote makes sense).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'm not going to do the typeof value thing -- since quotes seem fine above (see screenshot).

if (json_string.length > 10000) {
json_string = json_string.substring(0, 10000) + " (truncated)";
}
}
return (
<td
onMouseEnter={() => {
Expand Down Expand Up @@ -175,7 +182,7 @@ const VariableTable = (props: {
>
<div className="max-w-64 max-h-48 overflow-scroll scrollbar-hide">
<code className="whitespace-pre-wrap truncate">
{value?.toString()}
{json_string}
</code>
</div>
</td>
Expand Down
Loading