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
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using?
Python 3.8
What operating system and processor architecture are you using?
Snowflake Python UDF
What are the component versions in the environment (pip freeze)?
Only snowflake-snowpark-python
What did you do?
Using session.create_dataframe() does not work with an empty pandas.DataFrame object.
Here's the full code:
orders_table=session.table('orders')
pandas_df=orders_table.to_pandas()
filtered_pandas_df=pandas_df.loc[pandas_df['CUSTOMER_ID'] =='<DOESNT_EXIST>']
# filtered_df is an empty Pandas dataframe.snowpark_df=session.create_dataframe(filtered_pandas_df)
# Here I got an exception.
Here it is:
File~/work/venvs/snowpark/lib/python3.8/site-packages/snowflake/snowpark/session.py:1066, inSession.write_pandas(self, df, table_name, database, schema, chunk_size, compression, on_error, parallel, quote_identifiers, auto_create_table, create_temp_table, overwrite)
1060else:
1061location= (
1062 (database+"."ifdatabaseelse"")
1063+ (schema+"."ifschemaelse"")
1064+ (table_name)
1065 )
->1066success, nchunks, nrows, ci_output=write_pandas(
1067self._conn._conn,
1068df,
1069table_name,
1070database=database,
1071schema=schema,
1072chunk_size=chunk_size,
1073compression=compression,
1074on_error=on_error,
1075parallel=parallel,
1076quote_identifiers=quote_identifiers,
1077auto_create_table=auto_create_table,
1078create_temp_table=create_temp_table,
1079overwrite=overwrite,
1080 )
1081exceptProgrammingErroraspe:
1082ifpe.msg.endswith("does not exist"):
File~/work/venvs/snowpark/lib/python3.8/site-packages/snowflake/connector/pandas_tools.py:183, inwrite_pandas(conn, df, table_name,
database, schema, chunk_size, compression, on_error, parallel, quote_identifiers, auto_create_table, create_temp_table, overwrite, table_type)
180raise182withTemporaryDirectory() astmp_folder:
-->183fori, chunkinchunk_helper(df, chunk_size):
184chunk_path=os.path.join(tmp_folder, f"file{i}.txt")
185# Dump chunk into parquet file File~/work/venvs/snowpark/lib/python3.8/site-packages/snowflake/connector/pandas_tools.py:37, inchunk_helper(lst, n)
35defchunk_helper(lst: T, n: int) ->Iterator[tuple[int, T]]:
36"""Helper generator to chunk a sequence efficiently with current index like if enumerate was called on sequence."""--->37foriinrange(0, len(lst), n):
38yieldint(i/n), lst[i : i+n]
ValueError: range() arg3mustnotbezero
What did you expect to see?
I expected to get an empty snowflake.snowpark.DataFrame with the defined columns so that I'd be able to write it to a table with no rows.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
session.create_dataframe() crashes when the Pandas dataframe is empty.
SNOW-664933: session.create_dataframe() crashes when the Pandas dataframe is empty.
Sep 19, 2022
@elongl Thanks for your feedback! Ack it's a bug and we'll look into it. Meanwhile, if you want to have an empty Snowpark DataFrame with the defined columns, you can do:
Please answer these questions before submitting your issue. Thanks!
Python 3.8
Snowflake Python UDF
pip freeze
)?Only
snowflake-snowpark-python
Using
session.create_dataframe()
does not work with an emptypandas.DataFrame
object.Here's the full code:
Here it is:
I expected to get an empty
snowflake.snowpark.DataFrame
with the defined columns so that I'd be able to write it to a table with no rows.The text was updated successfully, but these errors were encountered: