Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a6fd8a0
SNOW-1856438: support cortex classify_text with apply
sfc-gh-lmukhopadhyay Dec 13, 2024
1c84edd
resolve conf
sfc-gh-lmukhopadhyay Jan 21, 2025
80fa2a5
use snowflake cortex function directly and remove snowpark functions
sfc-gh-lmukhopadhyay Jan 27, 2025
582623d
remove native snowpark cortex func tests
sfc-gh-lmukhopadhyay Jan 27, 2025
90acd1e
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 27, 2025
c8b3d10
add snowflake.cortex to setup
sfc-gh-lmukhopadhyay Jan 28, 2025
be3f0fb
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 28, 2025
2534b22
change to snowflake-ml-python pkg
sfc-gh-lmukhopadhyay Jan 28, 2025
e54bfe6
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 28, 2025
9d4c878
fix apply utils and add new test file
sfc-gh-lmukhopadhyay Jan 28, 2025
afbf924
neg test and fix is_supported_snowflake_cortex_function
sfc-gh-lmukhopadhyay Jan 29, 2025
0b3a458
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 29, 2025
11e1031
update changelog
sfc-gh-lmukhopadhyay Jan 29, 2025
8b46fd3
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 30, 2025
47b689c
update neg text to remove match
sfc-gh-lmukhopadhyay Jan 30, 2025
a7d0041
add support for apply cortex to df
sfc-gh-lmukhopadhyay Jan 31, 2025
d0abc8f
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Jan 31, 2025
a3f4be4
review changes
sfc-gh-lmukhopadhyay Feb 4, 2025
35a53ad
resolve conflics
sfc-gh-lmukhopadhyay Feb 4, 2025
74852a8
update neg test and qc apply methods
sfc-gh-lmukhopadhyay Feb 4, 2025
8974567
rev changes and support both args and kwargs in apply
sfc-gh-lmukhopadhyay Feb 5, 2025
c9890a4
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Feb 5, 2025
1173b66
generate cortex funcs and rev changes
sfc-gh-lmukhopadhyay Feb 5, 2025
48b1e97
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Feb 5, 2025
4035093
removing ClassifyText support
sfc-gh-lmukhopadhyay Feb 5, 2025
fdf3013
fix changelog
sfc-gh-lmukhopadhyay Feb 5, 2025
dd613d4
fix args unsupported test
sfc-gh-lmukhopadhyay Feb 6, 2025
29c548c
add back snowpark python functions and deprecation warning
sfc-gh-lmukhopadhyay Feb 6, 2025
6fb0f03
update deprecate warning and changelog
sfc-gh-lmukhopadhyay Feb 6, 2025
c4923fc
updating dependency setup for snowflake-ml-python
sfc-gh-lmukhopadhyay Feb 6, 2025
f7475f2
Merge branch 'main' into lmukhopadhyay-SNOW-1856438-cortex-funcs-apply
sfc-gh-lmukhopadhyay Feb 6, 2025
ef21755
cleanup comment
sfc-gh-lmukhopadhyay Feb 6, 2025
26dcef3
address comments
sfc-gh-lmukhopadhyay Feb 7, 2025
993c7dc
resolve conf
sfc-gh-lmukhopadhyay Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- `map_contains_key`
- `map_keys`
- `nullifzero`
- `snowflake_cortex_sentiment`
- `acosh`
- `asinh`
- `atanh`
Expand Down Expand Up @@ -89,14 +88,21 @@
- Fixed a bug in `replace` and `lit` which raised type hint assertion error when passing `Column` expression objects.
- Fixed a bug in `pandas_udf` and `pandas_udtf` where `session` parameter was erroneously ignored.

#### Removed Features

- Removed support for Snowpark Python function `snowflake_cortex_summarize`. Users can use the Summarize function from Snowflake.Cortex instead.

### Snowpark pandas API Updates

#### Dependency Updates

- Added a test dependency for `snowflake-ml-python`.

#### New Features

- Added support for `Series.str.ljust` and `Series.str.rjust`.
- Added support for `Series.str.center`.
- Added support for `Series.str.pad`.
- Added support for applying Snowpark Python function `snowflake_cortex_sentiment`.
- Added support for `DataFrame.map`.
- Added support for `DataFrame.from_dict` and `DataFrame.from_records`.
- Added support for mixed case field names in struct type columns.
Expand All @@ -121,6 +127,7 @@
- Added support for aggregations `"count"`, `"median"`, `np.median`,
`"skew"`, `"std"`, `np.std` `"var"`, and `np.var` in
`pd.pivot_table()`, `DataFrame.pivot_table()`, and `pd.crosstab()`.
- Added support for applying Snowflake Cortex functions `Summarize`, `Sentiment`, and `ClassifyText`.

#### Bug Fixes

Expand Down
2 changes: 0 additions & 2 deletions docs/source/snowpark/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ Functions
sinh
size
skew
snowflake_cortex_sentiment
snowflake_cortex_summarize
sort_array
soundex
split
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def run(self):
"scikit-learn", # Snowpark pandas 3rd party library testing
# plotly version restricted due to foreseen change in query counts in version 6.0.0+
"plotly<6.0.0", # Snowpark pandas 3rd party library testing
"snowflake-ml-python",
],
"localtest": [
"pandas",
Expand Down
30 changes: 0 additions & 30 deletions src/snowflake/snowpark/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10741,36 +10741,6 @@ def make_interval(
return res


def snowflake_cortex_summarize(text: ColumnOrLiteralStr):
"""
Summarizes the given English-language input text.

Args:
text: A string containing the English text from which a summary should be generated.

Returns:
A string containing a summary of the original text.
"""
sql_func_name = "snowflake.cortex.summarize"
text_col = _to_col_if_lit(text, sql_func_name)
return builtin(sql_func_name)(text_col)


def snowflake_cortex_sentiment(text: ColumnOrLiteralStr):
"""
A string containing the text for which a sentiment score should be calculated.

Args:
text: A string containing the English text from which a summary should be generated.
Returns:
A floating-point number from -1 to 1 (inclusive) indicating the level of negative or positive sentiment in the
text. Values around 0 indicate neutral sentiment.
"""
sql_func_name = "snowflake.cortex.sentiment"
text_col = _to_col_if_lit(text, sql_func_name)
return builtin(sql_func_name)(text_col)


@publicapi
def acosh(e: ColumnOrName, _emit_ast: bool = True) -> Column:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cloudpickle
import numpy as np
import pandas as native_pd
import snowflake.cortex
from pandas._typing import AggFuncType
from pandas.api.types import is_scalar

Expand Down Expand Up @@ -97,8 +98,12 @@
sp_func.floor,
sp_func.trunc,
sp_func.sqrt,
sp_func.snowflake_cortex_summarize,
sp_func.snowflake_cortex_sentiment,
}

SUPPORTED_SNOWFLAKE_CORTEX_FUNCTIONS_IN_APPLY = {
snowflake.cortex.ClassifyText,
snowflake.cortex.Summarize,
snowflake.cortex.Sentiment,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
is_supported_snowpark_python_function,
sort_apply_udtf_result_columns_by_pandas_positions,
make_series_map_snowpark_function,
SUPPORTED_SNOWFLAKE_CORTEX_FUNCTIONS_IN_APPLY,
)
from collections import defaultdict
from snowflake.snowpark.modin.plugin._internal.binary_op_utils import (
Expand Down Expand Up @@ -455,6 +456,32 @@

T = TypeVar("T", bound=Callable[..., Any])

_CORTEX_FUNC_NAMES = [
"ClassifyText",
"Complete",
"CompleteOptions",
"EmbedText1024",
"EmbedText768",
"ExtractAnswer",
"Finetune",
"FinetuneJob",
"FinetuneStatus",
"Sentiment",
"Summarize",
"Translate",
"_classify_text",
"_complete",
"_embed_text_1024",
"_embed_text_768",
"_extract_answer",
"_finetune",
"_sentiment",
"_sse_client",
"_summarize",
"_translate",
"_util",
]


def _propagate_attrs_on_methods(cls): # type: ignore
"""
Expand Down Expand Up @@ -8471,6 +8498,22 @@ def apply(
)
return self._apply_snowpark_python_function_to_columns(func, kwargs)

if func in SUPPORTED_SNOWFLAKE_CORTEX_FUNCTIONS_IN_APPLY:
if axis != 0:
ErrorMessage.not_implemented(
f"Snowpark pandas apply API doesn't yet support Snowflake Cortex function `{func.__name__}` with with axis = {axis}.'"
)
if raw is not False:
ErrorMessage.not_implemented(
f"Snowpark pandas apply API doesn't yet support Snowflake Cortex function `{func.__name__}`with raw = {raw}."
)
return self._apply_snowflake_cortex_function_to_columns(func, args, kwargs)
else:
if func.__name__ in _CORTEX_FUNC_NAMES:
ErrorMessage.not_implemented(
f"Snowpark pandas apply API doesn't yet support Snowflake Cortex function `{func.__name__}`"
)

sf_func = NUMPY_UNIVERSAL_FUNCTION_TO_SNOWFLAKE_FUNCTION.get(func)
if sf_func is not None:
return self._apply_snowpark_python_function_to_columns(sf_func, kwargs)
Expand Down Expand Up @@ -8786,6 +8829,29 @@ def sf_function(col: SnowparkColumn) -> SnowparkColumn:
self._modin_frame.apply_snowpark_function_to_columns(sf_function)
)

def _apply_snowflake_cortex_function_to_columns(
self,
snowflake_function: Callable,
args: tuple[Any, ...],
kwargs: dict[str, Any], # possible named arguments which need to be added
) -> "SnowflakeQueryCompiler":
"""Apply Snowflake Cortex function to columns."""

def sf_function(col: SnowparkColumn) -> SnowparkColumn:
resolved_positional = []
resolved_positional.append(col)
if args:
resolved_positional.append(args)
elif kwargs:
for arg in kwargs:
resolved_positional.append(kwargs[arg])

return snowflake_function(*resolved_positional)

return SnowflakeQueryCompiler(
self._modin_frame.apply_snowpark_function_to_columns(sf_function)
)

def applymap(
self,
func: AggFuncType,
Expand Down Expand Up @@ -8819,6 +8885,18 @@ def applymap(
)
return self._apply_snowpark_python_function_to_columns(func, kwargs)

if func in SUPPORTED_SNOWFLAKE_CORTEX_FUNCTIONS_IN_APPLY:
if na_action:
ErrorMessage.not_implemented(
f"Snowpark pandas applymap API doesn't yet support Snowflake Cortex function `{func.__name__}` with na_action == '{na_action}'"
)
return self._apply_snowflake_cortex_function_to_columns(func, args, kwargs)
else:
if func.__name__ in _CORTEX_FUNC_NAMES:
ErrorMessage.not_implemented(
f"Snowpark pandas apply API doesn't yet support Snowflake Cortex function `{func.__name__}`"
)

# Check if the function is a known numpy function that can be translated
# to Snowflake function.
sf_func = NUMPY_UNIVERSAL_FUNCTION_TO_SNOWFLAKE_FUNCTION.get(func)
Expand Down
Loading
Loading