Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Ideas

Share your Designer Desktop product ideas - we're listening!
Submitting an Idea?

Be sure to review our Idea Submission Guidelines for more information!

Submission Guidelines

Don't raise FileNotFoundError Exception in Python Tool, when no data is incoming

It seems that currently the Python tool is raising a `FileNotFoundError` exception in Python when there is not data incoming on an input connection. I have, for example, a Filter tool before the Python tool and sometimes there is just no data coming to Python tool - as it is intended.

 

Unfortunately, the Python tools gives my an error message in those cases with this message before the error:

 
Python (15)Unable to connect to input data (C:\Users\CCEB8~1.HAR\AppData\Local\Temp\3a9bb9672d7abbe6af3176379ae8c3b1\15\4460abb7be83bae8f01b9bf1238a923c.sqlite)

 

This is only the case when there is no data incoming. In all other cases, the tool works fine.

 

Since this is not really an error, a way to either catch this before using `Alteryx.read("#1")` or just having `Alteryx.read()` return an empty data.frame (as I would expect it to do) would be appreciated.

5 Comments
chrisha
11 - Bolide
I just noticed, that the problem is more serious than I've thought: If I run a workflow with data incoming to the Python tool, everything is fine. If I rerun the workflow in the same session and now no data is incoming to the Python tool, it re-uses the previous data. It seems to be still available in the temporary folder and the empty data is not written anywhere. In my understanding this presents a Race condition, that is a serious problem with workflows running regularly supposedly only on yet unseen data. I haven't been able to update to 2019.1 yet. But in the release notes I didn't see this issue addressed. Hopefully, it can be fixed in the next release?
troyfurnace
7 - Meteor

I was able to solve this using try/except in python.

 

Worth noting:

  1. It will write a python note of an error but thankfully not be treated as an alteryx error
  2. If this was to write out output, you'll need to create the output skeleton too (shown in example)

 

Code below demonstrates this (task is to silent delete any files passed in).  Breaking it down:

  • try/except/finally:
    • "try" tries to read the #1 stream, and set CanReadDataset to 1
    • "except" runs if it fails reading #1 (like empty rows) and sets CanReadDataset to 0
    • "finally" does nothing
  •  actual code you wanted to run:
    • all within a CanReadDataset == 1 check (in other words, if it was able to read the dataset)
    • note that if you got here, it has already read the #1 stream into df_in data stream (via the "try"); you don't need to do it again
  • the else condition writes the same schema as the expected output so that the surrounding Alteryx workflow has a constant schema coming out.

 

import os, stat, shutil, pandas

try:
    df_in = Alteryx.read("#1")
    CanReadDataset = 1
except:
    CanReadDataset = 0
finally:
    pass

if CanReadDataset == 1:
    for row in df_in.itertuples():
        FullPath = getattr(row, 'FullPath')
        if os.path.exists(FullPath):
            os.chmod(FullPath, stat.S_IWRITE)
            if os.path.isdir(FullPath):
                shutil.rmtree(FullPath)
            elif os.path.isfile(FullPath):
                os.remove(FullPath)
    df_out = df_in
else:
    df_out = pandas.DataFrame(columns=['FullPath'])
    
Alteryx.write(df_out,1)

 

 

 

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team
Status changed to: Accepting Votes
 
Joker_Hazard
11 - Bolide

Need a FIX ASAP!! 

carlhyde
5 - Atom

When you read a file with the name “filename.ext”; you are telling the open() function that your file is in the current working directory . This is called a relative path.

 

file = open('filename.ext') //relative path

 

In the above code, you are not giving the full path to a file to the open() function, just its name - a relative path. The error “FileNotFoundError: [Errno 2] No such file or directory” is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path.

 

file = open(r'C:\path\to\your\filename.ext') //absolute path

 

In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

If the user does not pass the full path to the file (on Unix type systems this means a path that starts with a slash), the python file path is interpreted relatively to the current working directory. The current working directory usually is the directory in which you started the program. In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are automatically used for searching executables when you enter a command. In any case, if your Python script file and your data input file are not in the same directory, you always have to specify either a relative path between them or you have to use an absolute path for one of them.