Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
node.generate_c()
out = _header
out += "// Extern declarations\n"
out += self._extern_declarations
out += "\n\n"
out += "// Global variables\n"
out += self._global_declarations
out += "\n"
out += "\n\n\n"
for fnbody in self._functions.values():
out += fnbody
out += "\n\n"
return out
sz_sint, sz_int, sz_lint, sz_llint, sz_sizet = core.get_integer_sizes()
t16 = ("int" if sz_int == 2 else
"short int" if sz_sint == 2 else "")
t32 = ("int" if sz_int == 4 else
"long int" if sz_lint == 4 else "")
t64 = ("int" if sz_int == 8 else
"long int" if sz_lint == 8 else
"long long int" if sz_llint == 8 else "")
tsz = (t32 if sz_sizet == 4 else
t64 if sz_sizet == 8 else "")
if not (t16 and t32 and t64 and tsz):
raise RuntimeError("Invalid integer sizes: short int(%d), int(%d), "
"long int(%d), long long int(%d), size_t(%d)"
% (sz_sint, sz_int, sz_lint, sz_llint, sz_sizet))
decl_sizes = "\n".join(["typedef signed char int8_t;",
"typedef %s int16_t;" % t16,
"typedef %s int16_t;" % t16,
"typedef %s int32_t;" % t32,
"typedef %s int64_t;" % t64,
"typedef unsigned char uint8_t;",
"typedef unsigned %s uint16_t;" % t16,
"typedef unsigned %s uint32_t;" % t32,
"typedef unsigned %s uint64_t;" % t64,
"typedef unsigned %s size_t;" % tsz])
(ptr_dt_malloc,
ptr_dt_realloc,
ptr_dt_free,
# ptr_rowindex_from_filterfn32,
ptr_dt_column_data,
ptr_dt_unpack_slicerowindex,
ptr_dt_unpack_arrayrowindex) = core.get_internal_function_ptrs()
_header = """
/**
* This code is auto-generated by context.py
**/
// Integer types
%s
#define NULL ((void*)0)
// External functions
typedef void* (*ptr_0)(size_t);
typedef void* (*ptr_1)(void*, size_t);
typedef void (*ptr_2)(void*);
typedef void* (*ptr_3)(void*, int64_t, int);
typedef void* (*ptr_4)(void*, int64_t);
warnings.warn(message, category=DatatableWarning)
def _showwarning(message, category, filename, lineno, file=None, line=None):
custom_handler = getattr(category, "_handle_", None)
if custom_handler:
custom_handler(message)
else:
_default_warnings_hoook(message, category, filename, lineno, file, line)
# Replace the default warnings handler
_default_warnings_hoook = warnings.showwarning
warnings.showwarning = _showwarning
core._register_function(4, TTypeError)
core._register_function(5, TValueError)
core._register_function(6, DatatableWarning)
__all__ = ("typed", "is_type", "U", "TTypeError", "TValueError", "TImportError",
"DatatableWarning", "dtwarn", "name_type")
def open(path):
if isinstance(path, bytes):
return core.open_jay(path)
if not isinstance(path, str):
raise TTypeError("Parameter `path` should be a string")
path = os.path.expanduser(path)
if not os.path.exists(path):
msg = "Path %s does not exist" % path
if not path.startswith("/"):
msg += " (current directory = %s)" % os.getcwd()
raise TValueError(msg)
if os.path.isdir(path):
raise TValueError("Path %s is a directory" % path)
return core.open_jay(path)
def _get_option(self, key):
kkey = self._prefix + key
if kkey in self._options:
return self._options[kkey]
msg = "Unknown datatable option `%s`" % kkey
alternatives = core.fuzzy_match(self._options, kkey)
if alternatives:
msg += "; did you mean %s?" % alternatives
raise DtAttributeError(msg)
assert grbynode is None
allrows = isinstance(rowsnode, AllRFNode)
# Without `materialize`, when an update is applied to a view,
# `rowsnode.execute()` will merge the rowindex implied by
# `rowsnode` with its parent's rowindex. This will cause the
# parent's data to be updated, which is wrong.
dt.materialize()
if isinstance(replacement, (int, float, str, type(None))):
replacement = datatable.Frame([replacement])
if allrows:
replacement = datatable.repeat(replacement, dt.nrows)
elif isinstance(replacement, datatable.Frame):
pass
elif isinstance(replacement, BaseExpr):
_col = replacement.evaluate_eager(ee)
_colset = core.columns_from_columns([_col])
replacement = _colset.to_frame(None)
else:
replacement = datatable.Frame(replacement)
rowsnode.execute()
colsnode.execute_update(dt, replacement)
return
rowsnode.execute()
if grbynode:
grbynode.execute(ee)
colsnode.execute()
res_dt = ee.columns.to_frame(colsnode.column_names)
if grbynode and res_dt.nrows == dt.nrows:
res_dt.internal.groupby = ee.groupby
return res_dt
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
from .expr import f, Expr, OpCodes
from datatable.lib import core
from builtins import abs as _builtin_abs
import math
__all__ = ("abs", "exp", "log", "log10", "isna")
# Deprecated, use math namespace instead
isna = core.isna
abs = core.abs
exp = core.exp
log = core.log
log10 = core.log10
def evaluate_eager(self, ee):
col = self.expr.evaluate_eager(ee)
opcode = reduce_opcodes["mean"]
return core.expr_reduceop(opcode, col, ee.groupby)
def isna(x):
if isinstance(x, BaseExpr):
return UnaryOpExpr("isna", x)
if isinstance(x, core.Frame):
if x.ncols != 1:
raise TTypeError("Frame must have a single column")
return x[:, isna(f[0])]
return (x is None) or (isinstance(x, float) and math.isnan(x))
def _make_source_rowindex(self):
return core.rowindex_from_array(self._array)