Hi Everyone,
I have a workflow and when run in alteryx designer it works well, but when I want to upload it to my company's server I get the metadata error as follows;
• --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[2], line 110 107 for col in df_out.columns: 108 metadata[col] = {'type': 'V_WString', 'length': 1000, 'source': 'PythonTool', 'description': ''} --> 110 Alteryx.write(df_out, 1, columns=metadata) File c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\ayx\export.py:87, in write(pandas_df, outgoing_connection_number, columns, debug, **kwargs) 83 def write(pandas_df, outgoing_connection_number, columns=None, debug=False, **kwargs): 84 """ 85 When running the workflow in Alteryx, this function will convert a pandas data frame to an Alteryx data stream and pass it out through one of the tool's five output anchors. When called from the Jupyter notebook interactively, it will display a preview of the pandas dataframe. An optional 'columns' argument allows column metadata to specify the field type, length, and name of columns in the output data stream. 86 """ ---> 87 return __CachedData__(debug=debug).write( 88 pandas_df, outgoing_connection_number, columns=columns, **kwargs 89 ) File c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\ayx\CachedData.py:641, in CachedData.write(self, pandas_df, outgoing_connection_number, columns, output_filepath) 636 msg_action = "writing outgoing connection data {}".format( 637 outgoing_connection_number 638 ) 639 try: 640 # get the data from the sql db (if only one table exists, no need to specify the table name) --> 641 data = db.writeData(pandas_df_out, metadata=write_metadata) 642 # print success message 643 if outgoing_connection_number is not None: File c:\program files\alteryx\bin\miniconda3\envs\designerbasetools_venv\lib\site-packages\ayx\Datafiles.py:733, in Datafile.writeData(self, pandas_df, metadata) 722 error_msg = msg_prefix.format( 723 " ".join( 724 [ (...) 730 ) 731 ) 732 print(error_msg) --> 733 raise TypeError(error_msg) 734 elif len(metadata) != len(pandas_df.columns): 735 error_msg = msg_prefix.format( 736 "metadata must have same number of columns as pandas_df" 737 ) TypeError: [Datafile.writeData]: metadata arg is required for yxdb and expected to be dict like {'Field1': {'type': 'FixedDecimal', 'length': (8, 3), 'source': 'PythonTool:', 'description': 'my description'}, 'Field2': {...}} (ToolId: 2)
This error happens because I connected a Python tool to a filter tool, so what could be the problem, guys??
The Python code from the Python tool (ToolID:2) is attached.
This has been unanswered for a few days and so I'll give you some things to look at.
It looks like the metadata being defined is not valid. I'll note the code provided defines the metadata as "metadata=metadata" whereas the error seems to define it correctly as "columns=metadata". However the error seems to indicate the variable [metadata] does not match the output. So, I would look there first.
Oh, well, I checked on that and used the dictionary it provided me with and also visited the Alteryx page. But I didn't get around the error, so I decided to drop the tools ahead of the Python tool and then perform their specific functions within the Python tool itself. So, it's solved for now, but the metadata args are not.