-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1690717 Applying Snowpark Python function (sin)
- Loading branch information
1 parent
141971b
commit 46409ec
Showing
4 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
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
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,51 @@ | ||
# | ||
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved. | ||
# | ||
|
||
import math | ||
|
||
import modin.pandas as pd | ||
import numpy as np | ||
import pandas as native_pd | ||
import pytest | ||
|
||
from tests.integ.modin.utils import assert_frame_equal, assert_series_equal | ||
from tests.integ.utils.sql_counter import sql_count_checker | ||
|
||
|
||
@sql_count_checker(query_count=4) | ||
def test_apply_sin(): | ||
from snowflake.snowpark.functions import sin | ||
|
||
native_s = native_pd.Series([0.00, -1.23, 10, math.pi, math.pi / 2]) | ||
s = pd.Series(native_s) | ||
|
||
assert_series_equal(s.apply(sin), native_s.apply(math.sin)) | ||
assert_series_equal(s.map(sin), native_s.map(math.sin)) | ||
assert_frame_equal( | ||
s.to_frame().applymap(sin), native_s.to_frame().applymap(math.sin) | ||
) | ||
assert_frame_equal( | ||
s.to_frame().apply(sin), | ||
native_s.to_frame().apply(np.sin), # Note math.sin does not work with df.apply | ||
) | ||
|
||
|
||
@sql_count_checker(query_count=0) | ||
def test_apply_snowpark_python_function_not_implemented(): | ||
from snowflake.snowpark.functions import cos, sin | ||
|
||
with pytest.raises(NotImplementedError): | ||
pd.Series([1, 2, 3]).apply(cos) | ||
with pytest.raises(NotImplementedError): | ||
pd.Series([1, 2, 3]).to_frame().applymap(sin, na_action="ignore") | ||
with pytest.raises(NotImplementedError): | ||
pd.Series([1, 2, 3]).to_frame().applymap(sin, args=[1, 2]) | ||
with pytest.raises(NotImplementedError): | ||
pd.DataFrame({"a": [1, 2, 3]}).apply(cos) | ||
with pytest.raises(NotImplementedError): | ||
pd.DataFrame({"a": [1, 2, 3]}).apply(sin, raw=True) | ||
with pytest.raises(NotImplementedError): | ||
pd.DataFrame({"a": [1, 2, 3]}).apply(sin, axis=1) | ||
with pytest.raises(NotImplementedError): | ||
pd.DataFrame({"a": [1, 2, 3]}).apply(sin, args=(1, 2)) |