numbarrow.core.configurations
Overview
numbarrow compiles its own numba functions, such as is_null() and the functions that read
Arrow buffers, with the options that this module holds. The NUMBARROW_JIT_OPTIONS environment variable sets them
as a JSON object, which numbarrow passes to @njit as keyword arguments. If the variable is unset or empty, the
options are {"cache": true}. Set the variable to turn on bounds checks while you debug, or to turn caching off
where numba cannot write a cache.
get_jit_options() reads and checks the variable. numbarrow calls it once, when this
module is first imported, and keeps the result in jit_options. The modules that you import from numbarrow, such as
numbarrow.core.adapters, all import this one, so set the variable before your program imports any of them. A
change after that import has no effect.
jit_with_options() is the decorator that numbarrow’s own functions use: @njit
with jit_options and a signature. If caching is on and numba cannot write a cache for a function, the decorator
compiles the function without one and issues a RuntimeWarning. The warning says how to get a cache: set
NUMBA_CACHE_DIR to a writable directory, or, if numbarrow is imported from an archive, install it unpacked or
import it from a .zip, which numba 0.61 and later can cache. NUMBARROW_JIT_OPTIONS='{"cache": false}' turns
caching off instead and silences the warning.
The README section on compilation and the cache explains when numba cannot write a cache, and why a change of
options needs a new NUMBA_CACHE_DIR while caching stays on.
Module
numbarrow’s njit options, and the decorator that compiles numbarrow’s functions with them.
get_jit_options() reads the options from the NUMBARROW_JIT_OPTIONS environment variable, and jit_options
holds what it returned when this module was first imported. Every function that numbarrow compiles goes through
jit_with_options(), which passes jit_options to numba’s njit. If numba cannot cache a function, the
decorator compiles it without a cache and warns.
- numbarrow.core.configurations.get_jit_options()[source]
Return the njit options that
NUMBARROW_JIT_OPTIONSsets, or{"cache": True}if it is unset or empty.The variable holds a JSON object, whose entries numbarrow passes to
njitas keyword arguments, unchanged:export NUMBARROW_JIT_OPTIONS='{"cache": false}'
The object replaces the default instead of adding to it, so
'{}'turns caching off. A value that is not a JSON object raisesValueError. So does a"cache"that is nottrueorfalse, and a string for any option but"error_model"and"inline", the two options that take a string. numba reads a non-empty string as true for a boolean option, so{"boundscheck": "false"}would turn bounds checks on.The function reads the variable each time it is called. The decorators use
jit_optionsinstead, which holds what the function returned when this module was first imported.The key under which numba’s on-disk cache stores compiled code does not include the options that the code was compiled with. A run that asks for other options therefore loads the code that an earlier run cached:
{"cache": true, "boundscheck": true}over a cache filled under the default options loads code without bounds checks. PointNUMBA_CACHE_DIRat a new directory when an option changes.
- numbarrow.core.configurations.invalid_jit_options_err = 'NUMBARROW_JIT_OPTIONS must be a JSON object, e.g., export NUMBARROW_JIT_OPTIONS=\'{"cache": false}\''
The text that begins the
ValueErrormessage for aNUMBARROW_JIT_OPTIONSvalue that is not a JSON object.
- numbarrow.core.configurations.jit_options = {'cache': True}
The njit options that
jit_with_options()passes to numba: whatget_jit_options()returned when this module was first imported.
- numbarrow.core.configurations.jit_with_options(signature)[source]
Return a decorator that compiles a function for
signaturewith numba’snjitandjit_options.numba compiles the function when the decorator is applied, because the signature is given. If caching is on and numba cannot cache the function, the decorator compiles it without a cache and issues a
RuntimeWarning. That happens for a read-only install, where numba can write neither in numbarrow’s own directory nor in the user’s cache directory, unlessNUMBA_CACHE_DIRnames a directory that it can write. It also happens for an import from an archive, such as an.eggthatspark-submit --py-filesputs on the workers’ path, or a.whlor.pyzfile placed onsys.path. From version 0.61, numba caches a module imported from a.zipand writes the cache to the user’s cache directory. The decorator then warns only if that directory cannot be written.The warning names a way to a cache. For a source file on disk, that is
NUMBA_CACHE_DIRset to a writable directory. numba ignoresNUMBA_CACHE_DIRfor a module in an archive, so there the warning names an unpacked install or a.zipinstead. In either case,NUMBARROW_JIT_OPTIONS='{"cache": false}'turns caching off and silences the warning. Any other error propagates, and so does every error with caching off.