Welcome to the Alteryx Knowledge Base
Created/Edited -
Dataframe returns an empty one when running the cell with the script in Jupyter Notebook, but returns output during workflow execution.
Configuration Example:
Code Example:
from ayx import Alteryx
df = Alteryx.read("#1")
print(df)
Alteryx.write(df,1)
The Results window shows an output after running the workflow.
The Output1 of the Python tool shows the data.
However, if you run the code in the cell in Jupyter Notebook, the dataframe returns an empty one:
- Alteryx Designer
- Version > 2022.1 and < 2024.2.1
NOTE: The issue can be seen in 2023.1, 2023.2 and 2024.2.1 with certain patches onwards.
How Python tool works in brief
Jupyter Notebook loads the workbook from a temporary working location. The temporary location contains the workbook and the configuration file at the start. During workflow execution, data files that go in and out of the Python tool are created in the same location. Alteryx.read() method reads data files from that location.
Cause of the issue
The issue happens as:
- A new temporary directory for Jupyter Notebook is created each time you step out of the Python tool, make changes in the code, etc This resets the working directory for the Jupyter Notebook and data files created during workflow execution will not be found. Please see this article for details on the temporary directory.
- In version < 2024.2.1, an additional empty data file is created for the in-stream tool to the Python tool in the temporary directory at the start. This is NOT seen in older Designer versions or in version 2024.2.1 or above. Data files should only be created after the workflow is executed.
Because of the above behaviours, Alteryx.read() method will return an empty dataframe if you run the cell in the Jupyter Notebook without running the workflow to pass the data from the in-stream tool to the Python tool. If you have executed the workflow and click the Python tool to run the cell, the dataframe should return data. However, if you click the Python tool after execution but step out anywhere, coming back to the Python tool will lose the in-stream data, as a new temp directory (with an empty data file) has been created. A defect (GCSE-3712) has been logged to address this.
NOTE: In version 2024.2.1 or above and some major versions (2023.1.1.123, 2024.1.1.17), instead of an empty dataframe, you will get the following error:
Unable to connect to input data (<TEMP><JUPYTER_DIRECTORY><INPUT_UID>.yxdb) You must run the workflow first in order to make a cached copy of the incoming data available for development purposes within this Jupyter notebook.Please consider one of the following suggestions.
Solution A: Upgrade Designer Version
An empty dataframe is not seen in version 2024.2.1 or above, but the "Unable to connect to input data" message will be seen.
NOTE: Upgrading the Designer version does not address the need to re-run the workflow to use the data in the Jupyter Notebook. Rather, the upgrade just serves as a reminder to run the workflow.
Solution B: For Version < 2024.2.1
To avoid getting an empty dataset in Jupyter Notebook, always run the workflow once before you run the cell if the in-stream tool to the Python tool does indeed contain records.