Skip to content

Commit

Permalink
Project import generated by Copybara. (#104)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: a6c37eeb0694bccabb7e846f9ae08441d3fd437f

Co-authored-by: Snowflake Authors <[email protected]>
  • Loading branch information
sfc-gh-anavalos and Snowflake Authors authored Jun 10, 2024
1 parent 2932445 commit 0634c4f
Show file tree
Hide file tree
Showing 62 changed files with 2,012 additions and 4,313 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release History

## 1.5.2

### Bug Fixes

- Registry: Fix an issue that leads to unable to log model in store procedure.
- Modeling: Quick fix `import snowflake.ml.modeling.parameters.enable_anonymous_sproc` cannot be imported due to package
dependency error.

### Behavior Changes

### New Features

## 1.5.1

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion ci/conda_recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build:
noarch: python
package:
name: snowflake-ml-python
version: 1.5.1
version: 1.5.2
requirements:
build:
- python
Expand Down
9 changes: 8 additions & 1 deletion codegen/sklearn_wrapper_template.py_template
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,14 @@ class {transform.original_class_name}(BaseTransformer):
) -> List[str]:
# in case the inferred output column names dimension is different
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
sample_pd_df = dataset.select(self.input_cols).limit(1).to_pandas()

# Rename the pandas df column names to snowflake identifiers and reorder columns to match the order
# seen during the fit.
snowpark_column_names = dataset.select(self.input_cols).columns
sample_pd_df.columns = snowpark_column_names

output_df_pd = getattr(self, method)(sample_pd_df, output_cols_prefix)
output_df_columns = list(output_df_pd.columns)
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
if self.sample_weight_col:
Expand Down
11 changes: 7 additions & 4 deletions snowflake/cortex/_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
def Sentiment(
text: Union[str, snowpark.Column], session: Optional[snowpark.Session] = None
) -> Union[str, snowpark.Column]:
) -> Union[float, snowpark.Column]:
"""Sentiment calls into the LLM inference service to perform sentiment analysis on the input text.
Args:
Expand All @@ -21,11 +21,14 @@ def Sentiment(
Returns:
A column of floats. 1 represents positive sentiment, -1 represents negative sentiment.
"""

return _sentiment_impl("snowflake.cortex.sentiment", text, session=session)


def _sentiment_impl(
function: str, text: Union[str, snowpark.Column], session: Optional[snowpark.Session] = None
) -> Union[str, snowpark.Column]:
return call_sql_function(function, session, text)
) -> Union[float, snowpark.Column]:

output = call_sql_function(function, session, text)
if isinstance(output, snowpark.Column):
return output
return float(output)
21 changes: 11 additions & 10 deletions snowflake/cortex/sentiment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,36 @@


class SentimentTest(absltest.TestCase):
prompt = "|prompt|"
sentiment = "0.53"

@staticmethod
def sentiment_for_test(prompt: str) -> str:
return f"result: {prompt}"
def sentiment_for_test(sentiment: str) -> float:
return float(sentiment)

def setUp(self) -> None:
self._session = _test_util.create_test_session()
functions.udf(
self.sentiment_for_test,
name="sentiment",
return_type=types.StringType(),
input_types=[types.StringType()],
session=self._session,
return_type=types.FloatType(),
input_types=[types.FloatType()],
is_permanent=False,
)

def tearDown(self) -> None:
self._session.sql("drop function sentiment(string)").collect()
self._session.sql("drop function sentiment(float)").collect()
self._session.close()

def test_sentiment_str(self) -> None:
res = _sentiment._sentiment_impl("sentiment", self.prompt)
self.assertEqual(self.sentiment_for_test(self.prompt), res)
res = _sentiment._sentiment_impl("sentiment", self.sentiment, session=self._session)
self.assertEqual(self.sentiment_for_test(self.sentiment), res)

def test_sentiment_column(self) -> None:
df_in = self._session.create_dataframe([snowpark.Row(prompt=self.prompt)])
df_in = self._session.create_dataframe([snowpark.Row(prompt=self.sentiment)])
df_out = df_in.select(_sentiment._sentiment_impl("sentiment", functions.col("prompt")))
res = df_out.collect()[0][0]
self.assertEqual(self.sentiment_for_test(self.prompt), res)
self.assertEqual(self.sentiment_for_test(self.sentiment), res)


if __name__ == "__main__":
Expand Down
7 changes: 5 additions & 2 deletions snowflake/ml/_internal/utils/temp_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
logger = logging.getLogger(__name__)


def get_temp_file_path() -> str:
def get_temp_file_path(prefix: str = "") -> str:
"""Returns a new random temp file path.
Args:
prefix: A prefix to the temp file path, this can help add stored file information. Defaults to None.
Returns:
A new temp file path.
"""
# TODO(snandamuri): Use in-memory filesystem for temp files.
local_file = tempfile.NamedTemporaryFile(delete=True)
local_file = tempfile.NamedTemporaryFile(prefix=prefix, delete=True)
local_file_name = local_file.name
local_file.close()
return local_file_name
Expand Down
Loading

0 comments on commit 0634c4f

Please sign in to comment.