-
Notifications
You must be signed in to change notification settings - Fork 109
add unit tests for expression functions #1121
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
add unit tests for expression functions #1121
Conversation
FYI @deanm0000 |
@mesejo @kosiew @chenkovsky @kevinjqliu Would any of you mind doing a review? We haven't released datafusion-python in a while and this is one of the PRs waiting to go in. 3/3 |
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.
Looks good.
I added some suggestions.
python/tests/test_expr.py
Outdated
def test_expr_functions(ctx, function, expected_result): | ||
ctx = SessionContext() |
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.
The second line can be deleted since ctx is available as a fixture
python/tests/test_expr.py
Outdated
), | ||
pytest.param( | ||
# Valid values of acosh must be >= 1.0 | ||
functions.round((col("a").abs() + lit(1.0)).abs().acosh(), lit(4)), |
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.
Second abs() is redundant since lit(1.0)) is already ≥ 0.
This can be simplified to:
functions.round((col("a").abs() + lit(1.0)).acosh(), lit(4))
python/tests/test_expr.py
Outdated
result = df.collect() | ||
|
||
assert len(result) == 1 | ||
assert result[0].column(0) == expected_result |
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.
Directly using assert result[0].column(0) == expected_result can be brittle for NaN or infinite values. Prefer Arrow’s built-in equality check:
assert result[0].column(0).equals(expected_result)
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.
LGTM!
python/tests/test_expr.py
Outdated
], | ||
) | ||
def test_expr_functions(ctx, function, expected_result): | ||
ctx = SessionContext() |
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.
ctx = SessionContext() |
python/tests/test_expr.py
Outdated
result = df.collect() | ||
|
||
assert len(result) == 1 | ||
assert result[0].column(0) == expected_result |
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.
assert result[0].column(0) == expected_result | |
assert result[0].column(0).equals(expected_result) |
Thank you all! Great suggestions. |
Which issue does this PR close?
Follow on to #1116
Rationale for this change
We don't have code coverage for these expression functions
What changes are included in this PR?
Unit tests
Are there any user-facing changes?
None