<#2753 [Plugin] Numpy dtypes integration> Issue cr...
# flyte-github
c
#2753 [Plugin] Numpy dtypes integration Issue created by cosmicBboy Currently, only numpy arrays are supported by the numpy type extension. It would be useful to also support scalar data types as well. So today, this code will not work: import numpy as np from flytekit import task, workflow @task def my_task() -> float: x = np.array([1,2,3]) return x.mean() @workflow def wf(): my_task() wf() Error:
Copy code
TypeError: Failed to convert return value for var o0 for function my_task with error <class 'flytekit.core.type_engine.TypeTransformerFailedError'>: Expected value of type <class 'float'> but got type <class 'numpy.float64'>
Problem: flytekit doesn't know how to handle
numpy.<dtype>
scalar types. The code above will show up anywhere where a user wants to aggregate some values using numpy operations (including sklearn, and probably a bunch of others) Of course the user can always do
float(x.mean())
to convert it to a normal float, but then this kills UX because now we're forcing users to modify otherwise functioning code into some flytekit-nitpicky syntax. ### Potential Solutions 1. Create a set of type transformers for numpy scalar dtypes 2. Modify existing primitive type transformers (see here) to recognize numpy types. #### Resources • numpy scalar types: https://numpy.org/doc/stable/reference/arrays.scalars.html flyteorg/flyte