.apply() and passing callables

Some pandas functions, like df.apply(f), support an arbitrary function as a parameter.

Most of the time, Terality will support these functions without any change.

In a few situations, Terality won't be able to transfer the arbitrary function defined in your code to the Terality servers. This page lists which scenarios are supported, and which are currently not.

Supported cases

Terality accepts functions (and lambdas) that depend on known modules:

  • functions from the Python 3.8 standard library:

from math import floor
# supported, function from the standard library
  • functions from pandas

  • functions from numpy:

import numpy as np

# supported, numpy function
  • functions (or lambdas) defined by the user in the current module:

def my_function_1(x):
    return x**2
def my_function_2(x):
    return 1 / (1 + my_function_1(x))

# supported, functions are all defined in the same module

# supported, lambdas are ok too
df.apply(lambda x: 1 / (1 + x^2))
  • and any combination of the supported cases mentioned previously

Unsupported cases

Terality currently does not support functions:

  • using third party dependencies other than numpy and pandas

  • defined in other modules:

from my_custom_module import my_custom_function

# Terality can not import such a function
  • referencing a Terality structure:

s = te.Series([0, 1, 2])
s2 = te.Series(["a", "b", "c"])

# unsupported
s.apply(lambda x: s2.iloc[x])

Additionally, functions with side effects (such as accessing the network or writing to disk) are not supported. They may return the correct result, raise an error, or silently return an incorrect result.

Last updated