title: How can I use a custom function within an expression using the eval dataframe method?
body: <p>I am using Python 3.X.</p>
  
  <p>With the builtin function <a href="https://docs.python.org/3/library/functions.html#eval" rel="noreferrer"><code>eval()</code></a> you can use a dictionaty of objects in order to use a custom function like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>from math import *
  
  def one():
      # some operations
      return 1
  
  functions = {
      '__builtins__': None,
      'sqrt': sqrt,
      'one': one,
  }
  variables = {
      '__builtins__': None,
      'pi': pi,
  }
  expression = 'sqrt(34 * pi) + one()'
  eval(expression, variables, functions)
  </code></pre>
  
  <p>But the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.eval.html#pandas.eval" rel="noreferrer"><code>eval()</code></a> dataframe method does not work like that. You can only use these built-in functions:</p>
  
  <blockquote>
    <p>The supported math functions are sin, cos, exp, log, expm1, log1p, sqrt, sinh, cosh, tanh, arcsin, arccos, arctan, arccosh, arcsinh, arctanh, abs and arctan2</p>
  </blockquote>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import numpy as np
  from math import *
  
  df = pd.DataFrame({
      'A': [0, 10, 0, 10, 10, 30],
      'B': [0, 0, 1000, 1000, 0, 0],
      'C': [25, 25, 25, 25, 40, 40]
  })
  
  def custom():
      # some operations
      return 3
  
  functions = {
      'custom': custom
  }
  variables = {
      'pi': pi
  }
  equation = 'D = sqrt(A) + B + custom()'
  df.eval(
      equation, global_dict=variables, local_dict=functions,
      engine='numexpr', inplace=True
  )
  # ERROR: "custom" is not a supported function
  </code></pre>
  
  <p>Is there a way to use a custom function in the expression?</p>
  
  <p>NOTE: I know it could bedangerous, but it is on me</p>