Understanding ?weird? running behavior with @vaex.register_func()
/ min row wise
#1550
-
Hi, Trying to extract min row wise for a variable number of columns, I ended up with following implementations. (@JovanVeljanoski , it works, at least in my test, do not try to find a bug. :) well I guess there isn't) import vaex as vx
import numpy as np
import pandas as pd
@vx.register_function()
def min_row_wise(*args):
print([col for col in args])
return np.min(np.stack(args, axis=1), axis=1)
# Test data
df = pd.DataFrame({'val1': [0.5, 1, 6.3],
'val2': [0.8, 1.2, 3.2],
'val3': [1.5, 1.9, 4.0]})
vdf = vx.from_pandas(df)
# And let the magic be!
vdf.func.min_row_wise(*[vdf[col] for col in vdf.get_column_names()]) When doing so, with the vdf.func.min_row_wise(*[vdf[col] for col in vdf.get_column_names()])
Out[45]:
[array([0.5]), array([0.8]), array([1.5])]
[array([0.5]), array([0.8]), array([1.5])]
[array([0.5]), array([0.8]), array([1.5])]
[array([0.5, 1. , 6.3]), array([0.8, 1.2, 3.2]), array([1.5, 1.9, 4. ])]
[array([0.5]), array([0.8]), array([1.5])]
Expression = min_row_wise(val1, val2, val3)
Length: 3 dtype: float64 (expression)
-------------------------------------
0 0.5
1 1
2 3.2
@JovanVeljanoski, please, would it be possible to have some insights about this? I thank you in advance for your feedback. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Nice work :) |
Beta Was this translation helpful? Give feedback.
Nice work :)
Yes, to determine the dtype of the function we execute it with an array of length 1. I hope in the future we do this less often, so this is expected for now.