-
Notifications
You must be signed in to change notification settings - Fork 155
feat: expose array_compact, array_normalize, cosine_distance, inner_product #1567
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
timsaucer
wants to merge
4
commits into
apache:main
Choose a base branch
from
timsaucer:feat/df54-array-distance-fns
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.
+233
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9a1e077
feat: expose array_compact, array_normalize, cosine_distance, inner_p…
timsaucer 2a9292e
docs: clarify array_normalize and cosine_distance docstrings
timsaucer 1755a78
test: add alias-equivalence and length-mismatch tests for array fns
timsaucer 40b788e
feat: expose dot_product alias for inner_product
timsaucer 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 |
|---|---|---|
|
|
@@ -717,6 +717,48 @@ def test_array_function_obj_tests(stmt, py_expr): | |
| assert a == b | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("alias_fn", "primary_fn", "data"), | ||
| [ | ||
| (f.list_compact, f.array_compact, [[1.0, None, 2.0, None, 3.0]]), | ||
| (f.list_normalize, f.array_normalize, [[3.0, 4.0]]), | ||
| ], | ||
| ) | ||
| def test_array_function_aliases(alias_fn, primary_fn, data): | ||
| """list_* helpers should be exact aliases for their array_* counterparts.""" | ||
| ctx = SessionContext() | ||
| df = ctx.from_pydict({"a": data}) | ||
| alias_result = df.select(alias_fn(column("a")).alias("r")).collect() | ||
| primary_result = df.select(primary_fn(column("a")).alias("r")).collect() | ||
| assert ( | ||
| alias_result[0].column(0).to_pylist() == primary_result[0].column(0).to_pylist() | ||
| ) | ||
|
|
||
|
|
||
| def test_dot_product_alias_matches_inner_product(): | ||
| """dot_product should be an exact alias for inner_product.""" | ||
|
Comment on lines
+738
to
+739
Contributor
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. Couldn't this test be adapted into the one above (might need to make |
||
| ctx = SessionContext() | ||
| df = ctx.from_pydict({"a": [[1.0, 2.0, 3.0]], "b": [[4.0, 5.0, 6.0]]}) | ||
| alias_result = df.select( | ||
| f.dot_product(column("a"), column("b")).alias("r") | ||
| ).collect() | ||
| primary_result = df.select( | ||
| f.inner_product(column("a"), column("b")).alias("r") | ||
| ).collect() | ||
| assert ( | ||
| alias_result[0].column(0).to_pylist() == primary_result[0].column(0).to_pylist() | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("fn", [f.cosine_distance, f.inner_product, f.dot_product]) | ||
| def test_array_distance_length_mismatch_raises(fn): | ||
| """Length-mismatched inputs to vector distance fns should raise at execute.""" | ||
| ctx = SessionContext() | ||
| df = ctx.from_pydict({"a": [[1.0, 2.0]], "b": [[1.0, 2.0, 3.0]]}) | ||
| with pytest.raises(Exception, match="same length"): | ||
| df.select(fn(column("a"), column("b")).alias("r")).collect() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("args", "expected"), | ||
| [ | ||
|
|
||
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.
There are many others list alias. Maybe in the future they could be added here.