You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to mock a non snowpark function (like greatest_ignore_nulls) results in an exception.
@patch("greatest_ignore_nulls")defmock_GREATEST_IGNORE_NULLS(*columns: Iterable[ColumnEmulator]) ->ColumnEmulator:
....
# Results in# NotImplementedError: [Local Testing] Function greatest_ignore_nulls is not supported in snowpark-python.
What is the desired behavior?
Same mocking API.
If this is not an existing feature in snowflake-snowpark-python. How would this impact/improve non-local testing mode?
This will be a complementary feature to using call_function.
References, Other Background
Additionally, it is not possible to mock call_function.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
Support mocking functions that are not supported in snowpark
SNOW-1623378: Support mocking functions that are not supported in snowpark
Aug 13, 2024
this is because greatest_ignore_nulls is not implemented in the snowpark python library, for now the patch only works for functions available in snowflake.snowpark.functions.
one workaround is to manually add a fake greatest_ignore_nulls function into the functions module as below:
importsnowflake.snowpark.functionsfromsnowflake.snowparkimportSession, Columnfromsnowflake.snowpark._internal.type_utilsimportColumnOrNamefromsnowflake.snowpark.functionsimportcall_functionfromsnowflake.snowpark.mockimportpatch, ColumnEmulator, ColumnTypefromsnowflake.snowpark.typesimportIntegerTypesession=Session.builder.configs({"local_testing": True}).create()
# this is just a placeholder, implementation does not matterdeffake_greatest_ignore_nulls(*columns: ColumnOrName) ->Column:
returnNone@patch("greatest_ignore_nulls")defmock_GREATEST_IGNORE_NULLS(*columns) ->ColumnEmulator:
returnColumnEmulator([1], sf_type=ColumnType(IntegerType(), nullable=False))
# dynamically add function to module so that local test can find itsnowflake.snowpark.functions.greatest_ignore_nulls=fake_greatest_ignore_nullsdf=session.create_dataframe(
[1, 2, 3, 4],
schema=["a"]
)
df.select(call_function("greatest_ignore_nulls", df["a"])).show()
I agree we should provide a better way to patch functions not defined in the functions.py module
What is the current behavior?
Trying to mock a non snowpark function (like
greatest_ignore_nulls
) results in an exception.What is the desired behavior?
Same mocking API.
If this is not an existing feature in
snowflake-snowpark-python
. How would this impact/improve non-local testing mode?This will be a complementary feature to using
call_function
.References, Other Background
Additionally, it is not possible to mock
call_function
.The text was updated successfully, but these errors were encountered: