[Data] Compute Expressions - Expr Trigonometric#59712
[Data] Compute Expressions - Expr Trigonometric#59712alexeykudinkin merged 6 commits intoray-project:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds trigonometric operations (sin, cos, tan, asin, acos, atan) to Ray Data Expressions. The implementation is clean and follows existing patterns. The tests cover the new functionality, but I've suggested a refactoring to improve their clarity, efficiency, and coverage by using a more explicit parameterization strategy.
owenowenisme
left a comment
There was a problem hiding this comment.
Hi @zzchun, CI is failing. Could you run pre-commit locally to fix the tests and push the updates?
Completing the Expr trigonometic operations (sin, cos, tan,
asin, acos, atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
Signed-off-by: will <zzchun8@gmail.com>
fed2bde to
7b9073e
Compare
|
Hi @owenowenisme @goutamvenkat-anyscale , could you please review this PR when you have a moment, thanks. |
Signed-off-by: Will Zhang <zzchun8@gmail.com>
Head branch was pushed to by a user without write access
| # For inverse trigonometric functions, we need to handle domain restrictions | ||
| # asin and acos require input in [-1, 1] | ||
| if expected_fn in (math.asin, math.acos): | ||
| # Use values in the valid domain for inverse trig functions | ||
| values = [-1.0, -0.5, 0.0, 0.5, 1.0] | ||
| ds = ray.data.from_items([{"value": v} for v in values]) | ||
|
|
There was a problem hiding this comment.
Nit: To improve the readability of this test, I think it might be clearer if we move this out into a separate test_with_column_inverse_trigonometric_operations test
## Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos,
atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
# Related issues
Related to #ray-project#58674
Signed-off-by: will <zzchun8@gmail.com>
Signed-off-by: Will Zhang <zzchun8@gmail.com>
Signed-off-by: jasonwrwang <jasonwrwang@tencent.com>
## Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos,
atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
# Related issues
Related to #ray-project#58674
Signed-off-by: will <zzchun8@gmail.com>
Signed-off-by: Will Zhang <zzchun8@gmail.com>
## Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos,
atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
# Related issues
Related to #ray-project#58674
Signed-off-by: will <zzchun8@gmail.com>
Signed-off-by: Will Zhang <zzchun8@gmail.com>
## Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos,
atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
# Related issues
Related to #ray-project#58674
Signed-off-by: will <zzchun8@gmail.com>
Signed-off-by: Will Zhang <zzchun8@gmail.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
## Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos,
atan)
for example:
```
import ray
from ray.data.expressions import col
import math
ds = ray.data.from_items([
{"angle": 0.0},
{"angle": math.pi / 4},
{"angle": math.pi / 2}
])
ds = ds.with_column("sin_value", col("angle").sin())
ds = ds.with_column("cos_value", col("angle").cos())
ds = ds.with_column("tan_value", col("angle").tan())
ds2 = ray.data.from_items([{"value": -1.0}, {"value": 0.0}, {"value": 1.0}])
ds2 = ds2.with_column("asin_result", col("value").asin())
ds2 = ds2.with_column("acos_result", col("value").acos())
ds2 = ds2.with_column("atan_result", col("value").atan())
```
# Related issues
Related to #ray-project#58674
Signed-off-by: will <zzchun8@gmail.com>
Signed-off-by: Will Zhang <zzchun8@gmail.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
Description
Completing the Expr trigonometic operations (sin, cos, tan, asin, acos, atan)
for example:
Related issues
Related to ##58674