For example, pandas’ read_excel()
method is overloaded on the sheet_name
parameter, ie. its behavior depends on the type of the value provided for this parameter. However, it seems Prefect will convert any Union type to a string. This results in an error from pandas.
Example (pseudo-code):
@flow
def pandas_fail(sheet_name: Optional[Union[str, list, int]):
df = pd.read_excel(sheet_name=sheet_name)
# Fails because 0 is converted to "0" and so
# pandas is looking for a sheet named "0".
pandas_fail(sheet_name=0)
I was wondering if there is any standard way of handling such parameters? What comes to my mind currently is custom to this particular pandas method: either to cast the value to the correct type inside the flow, or split the parameter into multiple ones, one for each allowed type (eg. sheet_name, sheet_number, sheets).