-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python function for column usage
- Loading branch information
Showing
6 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
|
||
import vegafusion as vf | ||
|
||
here = Path(__file__).parent | ||
|
||
spec_dir = here / ".." / ".." / "vegafusion-runtime" / "tests" / "specs" | ||
|
||
|
||
def test_get_column_usage(): | ||
spec_file = spec_dir / "vegalite" / "concat_marginal_histograms.vg.json" | ||
spec = json.loads(spec_file.read_text("utf8")) | ||
usages = vf.get_column_usage(spec) | ||
|
||
assert usages == {"source_0": ["IMDB Rating", "Rotten Tomatoes Rating"]} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any, cast | ||
|
||
from ._vegafusion import get_column_usage as _get_column_usage | ||
|
||
|
||
def get_column_usage(spec: dict[str, Any]) -> dict[str, list[str] | None]: | ||
""" | ||
Compute the columns from each root dataset that are referenced in a | ||
Vega spec. | ||
Args: | ||
spec: Vega spec | ||
Returns: | ||
dict[str, list[str] | None]: Dict from root-level dataset name | ||
to either: | ||
- A list of columns that are referenced in this dataset if this can | ||
be determined precisely | ||
- None if it was not possible to determine the full set of columns | ||
that are referenced from this dataset | ||
""" | ||
return cast("dict[str, list[str] | None]", _get_column_usage(spec)) |