You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I want to apply a function to all rows of a column. I want to raise an exception if a certain condition is met.
In pandas, I use the apply function.
I tried to use the apply function in vaex but I encountered a strange difficulty: I get a Key error. In my example, I just want the ValueError to be raised so that my unit tests work properly. What am I doing wrong?
Thank you!
Input file: text.txt (includes lines in between -----------------)
Output:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 113, in evaluate
result = self[expression]
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 198, in getitem
raise KeyError("Unknown variables or column: %r" % (variable,))
KeyError: "Unknown variables or column: 'lambda_function(X)'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 2273, in data_type
data = self.evaluate(expression, 0, 1, filtered=False, array_type=array_type, parallel=False)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 3095, in evaluate
return self._evaluate_implementation(expression, i1=i1, i2=i2, out=out, selection=selection, filtered=filtered, array_type=array_type, parallel=parallel, chunk_size=chunk_size, progress=progress)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 6562, in _evaluate_implementation
value = block_scope.evaluate(expression)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 119, in evaluate
result = eval(expression, expression_namespace, self)
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/arrow/numpy_dispatch.py", line 136, in wrapper
result = f(*args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1612, in call
return vaex.multiprocessing.apply(self._apply, args, kwargs, self.multiprocessing)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/multiprocessing.py", line 40, in apply
return f(args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1627, in _apply
scalar_result = self.f([fix_type(k[i]) for k in args], **{key: value[i] for key, value in kwargs.items()})
File "", line 3, in func
ValueError: 1 >= 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 113, in evaluate
result = self[expression]
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 198, in getitem
raise KeyError("Unknown variables or column: %r" % (variable,))
KeyError: "Unknown variables or column: 'lambda_function(X)'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 815, in repr
return self.repr_plain()
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 845, in repr_plain
dtype = self.dtype
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 506, in dtype
return self.df.data_type(self)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 2275, in data_type
data = self.evaluate(expression, 0, 1, filtered=True, array_type=array_type, parallel=False)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 3095, in evaluate
return self._evaluate_implementation(expression, i1=i1, i2=i2, out=out, selection=selection, filtered=filtered, array_type=array_type, parallel=parallel, chunk_size=chunk_size, progress=progress)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 6562, in _evaluate_implementation
value = block_scope.evaluate(expression)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 119, in evaluate
result = eval(expression, expression_namespace, self)
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/arrow/numpy_dispatch.py", line 136, in wrapper
result = f(*args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1612, in call
return vaex.multiprocessing.apply(self._apply, args, kwargs, self.multiprocessing)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/multiprocessing.py", line 40, in apply
return f(args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1627, in _apply
scalar_result = self.f([fix_type(k[i]) for k in args], **{key: value[i] for key, value in kwargs.items()})
File "", line 3, in func
ValueError: 1 >= 1
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I want to apply a function to all rows of a column. I want to raise an exception if a certain condition is met.
In pandas, I use the apply function.
I tried to use the apply function in vaex but I encountered a strange difficulty: I get a Key error. In my example, I just want the ValueError to be raised so that my unit tests work properly. What am I doing wrong?
Thank you!
Input file: text.txt (includes lines in between -----------------)
X
1
Code:
import vaex
df = vaex.from_csv("./text.txt",sep="\t",header=0)
def func(x):
if x>=1:
raise ValueError(F"{x} >= 1")
df.X.apply(func,multiprocessing=False)
Output:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 113, in evaluate
result = self[expression]
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 198, in getitem
raise KeyError("Unknown variables or column: %r" % (variable,))
KeyError: "Unknown variables or column: 'lambda_function(X)'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 2273, in data_type
data = self.evaluate(expression, 0, 1, filtered=False, array_type=array_type, parallel=False)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 3095, in evaluate
return self._evaluate_implementation(expression, i1=i1, i2=i2, out=out, selection=selection, filtered=filtered, array_type=array_type, parallel=parallel, chunk_size=chunk_size, progress=progress)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 6562, in _evaluate_implementation
value = block_scope.evaluate(expression)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 119, in evaluate
result = eval(expression, expression_namespace, self)
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/arrow/numpy_dispatch.py", line 136, in wrapper
result = f(*args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1612, in call
return vaex.multiprocessing.apply(self._apply, args, kwargs, self.multiprocessing)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/multiprocessing.py", line 40, in apply
return f(args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1627, in _apply
scalar_result = self.f([fix_type(k[i]) for k in args], **{key: value[i] for key, value in kwargs.items()})
File "", line 3, in func
ValueError: 1 >= 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 113, in evaluate
result = self[expression]
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 198, in getitem
raise KeyError("Unknown variables or column: %r" % (variable,))
KeyError: "Unknown variables or column: 'lambda_function(X)'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 815, in repr
return self.repr_plain()
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 845, in repr_plain
dtype = self.dtype
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 506, in dtype
return self.df.data_type(self)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 2275, in data_type
data = self.evaluate(expression, 0, 1, filtered=True, array_type=array_type, parallel=False)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 3095, in evaluate
return self._evaluate_implementation(expression, i1=i1, i2=i2, out=out, selection=selection, filtered=filtered, array_type=array_type, parallel=parallel, chunk_size=chunk_size, progress=progress)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/dataframe.py", line 6562, in _evaluate_implementation
value = block_scope.evaluate(expression)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/scopes.py", line 119, in evaluate
result = eval(expression, expression_namespace, self)
File "", line 1, in
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/arrow/numpy_dispatch.py", line 136, in wrapper
result = f(*args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1612, in call
return vaex.multiprocessing.apply(self._apply, args, kwargs, self.multiprocessing)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/multiprocessing.py", line 40, in apply
return f(args, **kwargs)
File "/home/m/miniconda3/envs/srablast/lib/python3.8/site-packages/vaex/expression.py", line 1627, in _apply
scalar_result = self.f([fix_type(k[i]) for k in args], **{key: value[i] for key, value in kwargs.items()})
File "", line 3, in func
ValueError: 1 >= 1
Beta Was this translation helpful? Give feedback.
All reactions