_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q267100 | assert_satisfies | test | def assert_satisfies(v, cond, message=None):
"""
Assert that variable satisfies the provided condition.
:param v: variable to check. Its value is only used for error reporting.
:param bool cond: condition that must be satisfied. Should be somehow related to the variable ``v``.
| python | {
"resource": ""
} |
q267101 | _retrieve_assert_arguments | test | def _retrieve_assert_arguments():
"""
Magic variable name retrieval.
This function is designed as a helper for assert_is_type() function. Typically such assertion is used like this::
assert_is_type(num_threads, int)
If the variable `num_threads` turns out to be non-integer, we would like to raise an exception such as
H2OTypeError("`num_threads` is expected to be integer, but got <str>")
and in order to compose an error message like that, we need to know that the variables that was passed to
assert_is_type() carries a name "num_threads". Naturally, the variable itself knows nothing about that.
This is where this function comes in: we walk up the stack trace until the first frame outside of this
file, find the original line that called the assert_is_type() function, and extract the variable name from
that line. This is slightly fragile, in particular we assume that only one assert_is_type statement can be per line,
or that this statement does not spill over multiple lines, etc.
"""
try:
raise RuntimeError("Catch me!")
except RuntimeError:
# Walk up the stacktrace until we are outside of this file
tb = sys.exc_info()[2]
assert tb.tb_frame.f_code.co_name == "_retrieve_assert_arguments"
this_filename = tb.tb_frame.f_code.co_filename
fr = tb.tb_frame
while fr is not None and fr.f_code.co_filename == this_filename:
fr = fr.f_back
# Read the source file and tokenize it, extracting the expressions.
try:
with io.open(fr.f_code.co_filename, "r", encoding="utf-8") as f:
# Skip initial lines that are irrelevant
for i in range(fr.f_lineno - 1): next(f)
# Create tokenizer
g = tokenize.generate_tokens(f.readline)
step = 0
args_tokens = []
level = 0
for ttt in g:
if step == 0:
| python | {
"resource": ""
} |
q267102 | _check_type | test | def _check_type(var, vtype):
"""
Return True if the variable is of the specified type, and False otherwise.
:param var: variable to check
:param vtype: expected variable's type
"""
if vtype is None:
return var is None
if isinstance(vtype, _primitive_type):
return var == vtype
if vtype is str:
return isinstance(var, _str_type)
if vtype is int:
return isinstance(var, _int_type)
if vtype is numeric:
return isinstance(var, _num_type)
if isinstance(vtype, MagicType):
return vtype.check(var)
if isinstance(vtype, type):
# ``vtype`` is a name of the class, or a built-in type such as "list", "tuple", etc
| python | {
"resource": ""
} |
q267103 | _get_type_name | test | def _get_type_name(vtype, dump=None):
"""
Return the name of the provided type.
_get_type_name(int) == "integer"
_get_type_name(str) == "string"
_get_type_name(tuple) == "tuple"
_get_type_name(Exception) == "Exception"
_get_type_name(U(int, float, bool)) == "integer|float|bool"
_get_type_name(U(H2OFrame, None)) == "?H2OFrame"
"""
if vtype is None:
return "None"
if vtype is str:
return "string"
if vtype is int:
return "integer"
if vtype is numeric:
return "numeric"
if is_type(vtype, str):
return '"%s"' % repr(vtype)[1:-1]
if is_type(vtype, int):
return str(vtype)
if isinstance(vtype, MagicType):
return vtype.name(dump)
if isinstance(vtype, type):
return vtype.__name__
if isinstance(vtype, list):
return "list(%s)" % _get_type_name(U(*vtype), dump)
| python | {
"resource": ""
} |
q267104 | _get_lambda_source_code | test | def _get_lambda_source_code(lambda_fn, src):
"""Attempt to find the source code of the ``lambda_fn`` within the string ``src``."""
def gen_lambdas():
def gen():
yield src + "\n"
g = gen()
step = 0
tokens = []
for tok in tokenize.generate_tokens(getattr(g, "next", getattr(g, "__next__", None))):
if step == 0:
if tok[0] == tokenize.NAME and tok[1] == "lambda":
step = 1
tokens = [tok]
level = 0
elif step == 1:
if tok[0] == tokenize.NAME:
tokens.append(tok)
step = 2
else:
| python | {
"resource": ""
} |
q267105 | NOT.check | test | def check(self, var):
"""Return True if the variable does not match any | python | {
"resource": ""
} |
q267106 | Enum.check | test | def check(self, var):
"""Check whether the provided value is a valid enum constant."""
| python | {
"resource": ""
} |
q267107 | H2OConfigReader.get_config | test | def get_config():
"""Retrieve the config as a dictionary of key-value pairs."""
| python | {
"resource": ""
} |
q267108 | H2OConfigReader._read_config | test | def _read_config(self):
"""Find and parse config file, storing all variables in ``self._config``."""
self._config_loaded = True
conf = []
for f in self._candidate_log_files():
if os.path.isfile(f):
self._logger.info("Reading config file %s" % f)
section_rx = re.compile(r"^\[(\w+)\]$")
keyvalue_rx = re.compile(r"^(\w+:)?([\w.]+)\s*=(.*)$")
with io.open(f, "rt", encoding="utf-8") as config_file:
section_name = None
for lineno, line in enumerate(config_file):
line = line.strip()
if line == "" or line.startswith("#"): continue
m1 = section_rx.match(line)
if m1:
section_name = m1.group(1)
continue
m2 = keyvalue_rx.match(line)
if m2:
lng = m2.group(1)
key = m2.group(2)
val = m2.group(3).strip()
if lng and lng.lower() | python | {
"resource": ""
} |
q267109 | H2OConfigReader._candidate_log_files | test | def _candidate_log_files():
"""Return possible locations for the .h2oconfig file, one at a time."""
# Search for .h2oconfig in the current directory and all parent directories
relpath = ".h2oconfig"
prevpath = None
while True:
abspath = os.path.abspath(relpath)
if abspath == prevpath: break
prevpath = abspath
| python | {
"resource": ""
} |
q267110 | ProgressBar.execute | test | def execute(self, progress_fn, print_verbose_info=None):
"""
Start the progress bar, and return only when the progress reaches 100%.
:param progress_fn: the executor function (or a generator). This function should take no arguments
and return either a single number -- the current progress level, or a tuple (progress level, delay),
where delay is the time interval for when the progress should be checked again. This function may at
any point raise the ``StopIteration(message)`` exception, which will interrupt the progress bar,
display the ``message`` in red font, and then re-raise the exception.
:raises StopIteration: if the job is interrupted. The reason for interruption is provided in the exception's
message. The message will say "cancelled" if the job was interrupted by the user by pressing Ctrl+C.
"""
assert_is_type(progress_fn, FunctionType, GeneratorType, MethodType)
if isinstance(progress_fn, GeneratorType):
# Convert generator to a regular function
progress_fn = (lambda g: lambda: next(g))(progress_fn)
# Initialize the execution context
self._next_poll_time = 0
self._t0 = time.time()
self._x0 = 0
self._v0 = 0.01 # corresponds to 100s completion time
self._ve = 0.01
progress = 0
status = None # Status message in case the job gets interrupted.
try:
while True:
# We attempt to synchronize all helper functions, ensuring that each of them has the same idea
# for what the current time moment is. Otherwise we could have some corner cases when one method
# says that something must happen right now, while the other already sees that moment in the past.
now = time.time()
# Query the progress level, but only if it's time already
if self._next_poll_time <= now:
res = progress_fn() # may raise StopIteration
assert_is_type(res, (numeric, numeric), numeric)
if not isinstance(res, tuple):
res = (res, -1)
# Progress querying could have taken some time, so update the current time moment
now = time.time()
| python | {
"resource": ""
} |
q267111 | ProgressBar._store_model_progress | test | def _store_model_progress(self, res, now):
"""
Save the current model progress into ``self._progress_data``, and update ``self._next_poll_time``.
:param res: tuple (progress level, poll delay).
:param now: current timestamp.
"""
raw_progress, delay = res
raw_progress = clamp(raw_progress, 0, self._maxval)
self._progress_data.append((now, raw_progress))
if delay < 0:
| python | {
"resource": ""
} |
q267112 | ProgressBar._recalculate_model_parameters | test | def _recalculate_model_parameters(self, now):
"""Compute t0, x0, v0, ve."""
time_until_end = self._estimate_progress_completion_time(now) - now
assert time_until_end >= 0, "Estimated progress completion cannot be in the past."
x_real = self._get_real_progress()
if x_real == 1:
t0, x0, v0, ve = now, 1, 0, 0
else:
x0, v0 = self._compute_progress_at_time(now)
t0 = now
if x0 >= 1:
# On rare occasion, the model's progress may have reached 100% by ``now``. This can happen if
# (1) the progress is close to 100% initially and has high speed, (2) on the previous call we
# estimated that the process completion time will be right after the next poll time, and (3)
# the polling itself took so much time that the process effectively "overshoot".
# If this happens, then we adjust x0, v0 to the previous valid data checkpoint.
t0, x0, v0 = self._t0, self._x0, self._v0
time_until_end += now - t0
| python | {
"resource": ""
} |
q267113 | ProgressBar._estimate_progress_completion_time | test | def _estimate_progress_completion_time(self, now):
"""
Estimate the moment when the underlying process is expected to reach completion.
This function should only return future times. Also this function is not allowed to return time moments less
than self._next_poll_time if the actual progress is below 100% (this is because we won't know that the
process have finished until we poll the external progress function).
"""
assert self._next_poll_time >= now
tlast, wlast = self._progress_data[-1]
# If reached 100%, make sure that we finish as soon as possible, but maybe not immediately
if wlast == self._maxval:
current_completion_time = (1 - self._x0) / self._v0 + self._t0
return clamp(current_completion_time, now, now + self.FINISH_DELAY)
# Calculate the approximate speed of the raw progress based on recent data
tacc, wacc = 0, 0
factor = self.GAMMA
for t, x in self._progress_data[-2::-1]:
tacc += factor * (tlast - t)
wacc += factor * (wlast - x) | python | {
"resource": ""
} |
q267114 | ProgressBar._guess_next_poll_interval | test | def _guess_next_poll_interval(self):
"""
Determine when to query the progress status next.
This function is used if the external progress function did not return time interval for when it should be
queried next.
"""
time_elapsed = | python | {
"resource": ""
} |
q267115 | ProgressBar._compute_progress_at_time | test | def _compute_progress_at_time(self, t):
"""
Calculate the modelled progress state for the given time moment.
:returns: tuple (x, v) of the progress level and progress speed.
"""
t0, x0, v0, ve = self._t0, self._x0, self._v0, self._ve
| python | {
"resource": ""
} |
q267116 | ProgressBar._get_time_at_progress | test | def _get_time_at_progress(self, x_target):
"""
Return the projected time when progress level `x_target` will be reached.
Since the underlying progress model is nonlinear, we need to do use Newton method to find a numerical solution
to the equation x(t) = x_target.
"""
t, x, v = self._t0, self._x0, self._v0
# The convergence should be achieved in just few iterations, however in unlikely situation that it doesn't
# we don't want to loop forever...
for _ in range(20):
if v == 0: return 1e20
# make | python | {
"resource": ""
} |
q267117 | ProgressBar._draw | test | def _draw(self, txt, final=False):
"""Print the rendered string to the stdout."""
if not self._file_mode:
# If the user presses Ctrl+C this ensures we still start writing from the beginning of the line
sys.stdout.write("\r")
sys.stdout.write(txt)
if final | python | {
"resource": ""
} |
q267118 | _ProgressBarCompoundWidget._compute_widget_sizes | test | def _compute_widget_sizes(self):
"""Initial rendering stage, done in order to compute widths of all widgets."""
wl = [0] * len(self._widgets)
flex_count = 0
# First render all non-flexible widgets
for i, widget in enumerate(self._widgets):
if isinstance(widget, ProgressBarFlexibleWidget):
flex_count += 1
else:
wl[i] = widget.render(1).length
remaining_width = self._width - sum(wl)
remaining_width -= len(self._widgets) - 1 # account for 1-space interval between widgets
if remaining_width < 10 * flex_count:
if self._file_mode:
remaining_width = 10 * flex_count
else:
# The window is too small to accomodate the widget: try to split it into several lines, otherwise
# switch to "file mode". If we don't do this, then rendering the widget will cause it to wrap, and
# then when we use \r to go to the beginning of the line, only part of the widget will be overwritten,
# which means we'll have many (possibly hundreds) of progress bar lines in the end.
widget0 = self._widgets[0]
if isinstance(widget0, PBWString) and remaining_width + widget0.render(0).length >= 10 * flex_count:
| python | {
"resource": ""
} |
q267119 | _ProgressBarCompoundWidget._get_terminal_size | test | def _get_terminal_size():
"""Find current STDOUT's width, in characters."""
# If output is not terminal but a regular file, assume 100 chars width
if not sys.stdout.isatty():
return 80
# Otherwise, first try getting the dimensions from shell command `stty`:
try:
import subprocess
ret = subprocess.check_output(["stty", "size"]).strip().split(" ")
if len(ret) == 2:
return int(ret[1])
except:
pass
# Otherwise try using ioctl
| python | {
"resource": ""
} |
q267120 | PBWBar.set_encoding | test | def set_encoding(self, encoding):
"""Inform the widget about the encoding of the underlying character stream."""
self._bar_ends = "[]"
self._bar_symbols = "#"
if not encoding: return
s1 = "\u258F\u258E\u258D\u258C\u258B\u258A\u2589\u2588"
s2 = "\u258C\u2588"
s3 = "\u2588"
if self._file_mode:
s1 = s2 = None
assert len(s3) == 1
for s in (s1, s2, s3):
if s is None: continue | python | {
"resource": ""
} |
q267121 | TargetEncoder.fit | test | def fit(self, frame = None):
"""
Returns encoding map as an object that maps 'column_name' -> 'frame_with_encoding_map_for_this_column_name'
:param frame frame: An H2OFrame object with which to create the target encoding map
"""
self._teColumns = list(map(lambda i: frame.names[i], self._teColumns)) if all(isinstance(n, int) for n in | python | {
"resource": ""
} |
q267122 | H2OFrame.get_frame | test | def get_frame(frame_id, rows=10, rows_offset=0, cols=-1, full_cols=-1, cols_offset=0, light=False):
"""
Retrieve an existing H2OFrame from the H2O cluster using the frame's id.
:param str frame_id: id of the frame to retrieve
:param int rows: number of rows to fetch for preview (10 by default)
:param int rows_offset: offset to fetch rows from (0 by default)
:param int cols: number of columns to fetch (all by default)
:param full_cols: number of columns to fetch together with backed data
:param int cols_offset: offset to fetch rows from (0 by default)
:param bool light: wether to use light frame endpoint or not
:returns: an | python | {
"resource": ""
} |
q267123 | H2OFrame.refresh | test | def refresh(self):
"""Reload frame information from the backend H2O server."""
| python | {
"resource": ""
} |
q267124 | H2OFrame.type | test | def type(self, col):
"""
The type for the given column.
:param col: either a name, or an index of the column to look up
:returns: type of the column, one of: ``str``, ``int``, ``real``, ``enum``, ``time``, ``bool``.
:raises H2OValueError: if such column does not exist in the frame.
"""
assert_is_type(col, int, str)
if not self._ex._cache.types_valid() or not self._ex._cache.names_valid():
self._ex._cache.flush()
self._frame(fill_cache=True)
types = self._ex._cache.types
if is_type(col, str):
| python | {
"resource": ""
} |
q267125 | H2OFrame.columns_by_type | test | def columns_by_type(self, coltype="numeric"):
"""
Extract columns of the specified type from the frame.
:param str coltype: A character string indicating which column type to filter by. This must be
one of the following:
- ``"numeric"`` - Numeric, but not categorical or time
- ``"categorical"`` - Integer, with a categorical/factor String mapping
- ``"string"`` - String column
- ``"time"`` - Long msec since the Unix Epoch - with a variety of display/parse options
| python | {
"resource": ""
} |
q267126 | H2OFrame.summary | test | def summary(self, return_data=False):
"""
Display summary information about the frame.
Summary includes min/mean/max/sigma and other rollup data.
:param bool return_data: Return a dictionary of the summary output
"""
if not self._has_content():
print("This H2OFrame is empty and not initialized.")
return self._ex._cache._data;
if not self._ex._cache.is_valid(): self._frame()._ex._cache.fill()
if not return_data:
if self.nrows == 0:
print("This H2OFrame is empty.") | python | {
"resource": ""
} |
q267127 | H2OFrame.describe | test | def describe(self, chunk_summary=False):
"""
Generate an in-depth description of this H2OFrame.
This will print to the console the dimensions of the frame; names/types/summary statistics for each column;
and finally first ten rows of the frame.
:param bool chunk_summary: Retrieve the chunk summary along with the distribution summary
"""
if self._has_content():
res = h2o.api("GET /3/Frames/%s" % self.frame_id, data={"row_count": 10})["frames"][0]
self._ex._cache._fill_data(res)
print("Rows:{}".format(self.nrow))
| python | {
"resource": ""
} |
q267128 | H2OFrame.head | test | def head(self, rows=10, cols=200):
"""
Return the first ``rows`` and ``cols`` of the frame as a new H2OFrame.
:param int rows: maximum number of rows to return
:param int cols: maximum number of columns to return
:returns: a new H2OFrame cut from the top left corner of the current frame, and having dimensions at
most ``rows`` x ``cols``.
| python | {
"resource": ""
} |
q267129 | H2OFrame.mult | test | def mult(self, matrix):
"""
Multiply this frame, viewed as a matrix, by another matrix.
:param matrix: another frame that you want to multiply the current frame by; must be compatible with the
current frame (i.e. its number of rows must be the same as number of columns in the current frame).
:returns: new H2OFrame, which is the result of multiplying the current frame by ``matrix``. | python | {
"resource": ""
} |
q267130 | H2OFrame.levels | test | def levels(self):
"""
Get the factor levels.
:returns: A list of lists, one list per column, of levels.
"""
lol = H2OFrame._expr(expr=ExprNode("levels", self)).as_data_frame(False)
| python | {
"resource": ""
} |
q267131 | H2OFrame.nlevels | test | def nlevels(self):
"""
Get the number of factor levels for each categorical column.
| python | {
"resource": ""
} |
q267132 | H2OFrame.set_level | test | def set_level(self, level):
"""
A method to set all column values to one of the levels.
:param str level: The level at which the column will be set (a string)
:returns: | python | {
"resource": ""
} |
q267133 | H2OFrame.set_levels | test | def set_levels(self, levels):
"""
Replace the levels of a categorical column.
New levels must be aligned with the old domain. This call has copy-on-write semantics.
:param List[str] levels: A list of strings specifying the new levels. The number of new
levels must match the number of old levels.
| python | {
"resource": ""
} |
q267134 | H2OFrame.rename | test | def rename(self, columns=None):
"""
Change names of columns in the frame.
Dict key is an index or name of the column whose name is to be set.
Dict value is the new name of the column.
:param columns: dict-like transformations to apply to the column names
"""
assert_is_type(columns, None, dict)
new_names = self.names
ncols = self.ncols
for col, name in columns.items():
col_index = None
if is_type(col, int) and (-ncols <= col < ncols):
| python | {
"resource": ""
} |
q267135 | H2OFrame.set_names | test | def set_names(self, names):
"""
Change names of all columns in the frame.
:param List[str] names: The list of new names for every column in the frame.
"""
assert_is_type(names, [str])
assert_satisfies(names, len(names) == self.ncol)
| python | {
"resource": ""
} |
q267136 | H2OFrame.set_name | test | def set_name(self, col=None, name=None):
"""
Set a new name for a column.
:param col: index or name of the column whose name is to be set; may be skipped for 1-column frames
:param name: the new name of the column
"""
assert_is_type(col, None, int, str)
assert_is_type(name, str)
ncols = self.ncols
col_index = None
if is_type(col, int):
if not(-ncols <= col < ncols):
raise H2OValueError("Index %d is out of bounds for a frame with %d columns" % (col, ncols))
col_index = (col + ncols) % ncols # handle negative indices
elif is_type(col, str):
if col not in self.names:
raise H2OValueError("Column %s doesn't exist in the frame." % col)
col_index = self.names.index(col) # lookup the name
else:
assert col is None
if ncols != 1:
raise H2OValueError("The frame has %d columns; please specify which one to rename" % ncols)
col_index = 0
| python | {
"resource": ""
} |
q267137 | H2OFrame.isin | test | def isin(self, item):
"""
Test whether elements of an H2OFrame are contained in the ``item``.
:param items: An item or a list of items to compare the H2OFrame against.
:returns: An H2OFrame of 0s and 1s showing whether each element in the original H2OFrame is contained in item.
"""
if is_type(item, list, tuple, set):
| python | {
"resource": ""
} |
q267138 | H2OFrame.modulo_kfold_column | test | def modulo_kfold_column(self, n_folds=3):
"""
Build a fold assignments column for cross-validation.
Rows are assigned a fold according to the current row number modulo ``n_folds``.
:param int n_folds: An integer specifying the number of validation sets to split the training data into.
:returns: A | python | {
"resource": ""
} |
q267139 | H2OFrame.stratified_kfold_column | test | def stratified_kfold_column(self, n_folds=3, seed=-1):
"""
Build a fold assignment column with the constraint that each fold has the same class
distribution as the fold column.
:param int n_folds: The number of folds to build.
:param int seed: A seed for the random number generator.
| python | {
"resource": ""
} |
q267140 | H2OFrame.structure | test | def structure(self):
"""Compactly display the internal structure of an H2OFrame."""
df = self.as_data_frame(use_pandas=False)
cn = df.pop(0)
nr = self.nrow
nc = self.ncol
width = max([len(c) for c in cn])
isfactor = self.isfactor()
numlevels = self.nlevels()
lvls = self.levels()
print("H2OFrame: '{}' \nDimensions: {} obs. of {} variables".format(self.frame_id, nr, nc))
for i in range(nc):
print("$ {} {}: ".format(cn[i], ' ' * (width - max(0, len(cn[i])))), end=' ')
if isfactor[i]:
| python | {
"resource": ""
} |
q267141 | H2OFrame.as_data_frame | test | def as_data_frame(self, use_pandas=True, header=True):
"""
Obtain the dataset as a python-local object.
:param bool use_pandas: If True (default) then return the H2OFrame as a pandas DataFrame (requires that the
``pandas`` library was installed). If False, then return the contents of the H2OFrame as plain nested
list, in a row-wise order.
:param bool header: If True (default), then column names will be appended as the first row in list
:returns: A python object (a list of lists of strings, each list is a row, if use_pandas=False, otherwise
a pandas DataFrame) containing this H2OFrame instance's data.
"""
| python | {
"resource": ""
} |
q267142 | H2OFrame.pop | test | def pop(self, i):
"""
Pop a column from the H2OFrame at index i.
:param i: The index (int) or name (str) of the column to pop.
:returns: an H2OFrame containing the column dropped from the current frame; the current frame is modified
in-place and loses the column.
"""
if is_type(i, str): i = self.names.index(i)
| python | {
"resource": ""
} |
q267143 | H2OFrame.quantile | test | def quantile(self, prob=None, combine_method="interpolate", weights_column=None):
"""
Compute quantiles.
:param List[float] prob: list of probabilities for which quantiles should be computed.
:param str combine_method: for even samples this setting determines how to combine quantiles. This can be
one of ``"interpolate"``, ``"average"``, ``"low"``, ``"high"``.
:param weights_column: optional weights for each row. If not given, all rows are assumed to have equal
importance. This parameter can be either the name of column containing the observation weights in
| python | {
"resource": ""
} |
q267144 | H2OFrame.concat | test | def concat(self, frames, axis=1):
"""
Append multiple H2OFrames to this frame, column-wise or row-wise.
:param List[H2OFrame] frames: list of frames that should be appended to the current frame.
:param int axis: if 1 then append column-wise (default), if 0 then append row-wise.
:returns: an H2OFrame of the combined datasets.
"""
| python | {
"resource": ""
} |
q267145 | H2OFrame.cbind | test | def cbind(self, data):
"""
Append data to this frame column-wise.
:param H2OFrame data: append columns of frame ``data`` to the current frame. You can also cbind a number,
in which case it will get converted into a constant column.
:returns: new H2OFrame with all frames in ``data`` appended column-wise.
"""
assert_is_type(data, H2OFrame, numeric, [H2OFrame, numeric])
frames = [data] if not isinstance(data, list) else data
new_cols = list(self.columns)
new_types = dict(self.types)
for frame in frames:
if isinstance(frame, H2OFrame):
if frame.nrow != self.nrow:
raise H2OValueError("Cannot bind a dataframe with %d rows to a data frame with %d rows: "
"the number of rows should match" % (frame.nrow, self.nrow))
new_cols += frame.columns
new_types.update(frame.types)
| python | {
"resource": ""
} |
q267146 | H2OFrame.rbind | test | def rbind(self, data):
"""
Append data to this frame row-wise.
:param data: an H2OFrame or a list of H2OFrame's to be combined with current frame row-wise.
:returns: this H2OFrame with all frames in data appended row-wise.
"""
assert_is_type(data, H2OFrame, [H2OFrame])
frames = [data] if not isinstance(data, list) else data
for frame in frames:
if frame.ncol != self.ncol:
raise H2OValueError("Cannot row-bind a dataframe with %d columns to a data frame with %d columns: "
| python | {
"resource": ""
} |
q267147 | H2OFrame.split_frame | test | def split_frame(self, ratios=None, destination_frames=None, seed=None):
"""
Split a frame into distinct subsets of size determined by the given ratios.
The number of subsets is always 1 more than the number of ratios given. Note that
this does not give an exact split. H2O is designed to be efficient on big data
using a probabilistic splitting method rather than an exact split. For example
when specifying a split of 0.75/0.25, H2O will produce a test/train split with
an expected value of 0.75/0.25 rather than exactly 0.75/0.25. On small datasets,
the sizes of the resulting splits will deviate from the expected value more than
on big data, where they will be very close to exact.
:param List[float] ratios: The fractions of rows for each split.
:param List[str] destination_frames: The names of the split frames.
:param int seed: seed for the random number generator
:returns: A list of H2OFrames
"""
assert_is_type(ratios, [numeric], None)
assert_is_type(destination_frames, [str], None)
assert_is_type(seed, int, None)
if ratios is None:
ratios = [0.75]
if not ratios:
raise ValueError("Ratios array may not be empty")
if destination_frames is not None:
if len(ratios) + 1 != len(destination_frames):
raise ValueError("The number of provided destination_frames must be one more "
"than the number of provided ratios")
num_slices = len(ratios) + 1
boundaries = []
last_boundary = 0
i = 0
while i < num_slices - 1:
ratio = ratios[i]
if ratio < 0:
raise ValueError("Ratio must be greater than 0")
boundary = last_boundary + ratio
if boundary >= 1.0:
raise ValueError("Ratios must add up to less than 1.0")
boundaries.append(boundary)
| python | {
"resource": ""
} |
q267148 | H2OFrame.group_by | test | def group_by(self, by):
"""
Return a new ``GroupBy`` object using this frame and the desired grouping columns.
The returned groups are sorted by the natural group-by column | python | {
"resource": ""
} |
q267149 | H2OFrame.fillna | test | def fillna(self,method="forward",axis=0,maxlen=1):
"""
Return a new Frame that fills NA along a given axis and along a given direction with a maximum fill length
:param method: ``"forward"`` or ``"backward"``
| python | {
"resource": ""
} |
q267150 | H2OFrame.impute | test | def impute(self, column=-1, method="mean", combine_method="interpolate", by=None, group_by_frame=None, values=None):
"""
Impute missing values into the frame, modifying it in-place.
:param int column: Index of the column to impute, or -1 to impute the entire frame.
:param str method: The method of imputation: ``"mean"``, ``"median"``, or ``"mode"``.
:param str combine_method: When the method is ``"median"``, this setting dictates how to combine quantiles
for even samples. One of ``"interpolate"``, ``"average"``, ``"low"``, ``"high"``.
:param by: The list of columns to group on.
:param H2OFrame group_by_frame: Impute the values with this pre-computed grouped frame.
:param List values: The list of impute values, one per column. None indicates to skip the column.
:returns: A list of values used in the imputation or the group-by result used in imputation.
"""
if is_type(column, str): column = self.names.index(column)
if is_type(by, str): by = self.names.index(by)
if values is None:
values = "_"
else:
assert len(values) == len(self.columns), "Length of values does not match length of columns"
# convert string values to categorical num values
values2 = []
for i in range(0,len(values)):
if self.type(i) == "enum":
try:
values2.append(self.levels()[i].index(values[i]))
except:
raise H2OValueError("Impute value of: " + values[i] + " not found in existing levels of"
" column: " + self.col_names[i])
| python | {
"resource": ""
} |
q267151 | H2OFrame.merge | test | def merge(self, other, all_x=False, all_y=False, by_x=None, by_y=None, method="auto"):
"""
Merge two datasets based on common column names. We do not support all_x=True and all_y=True.
Only one can be True or none is True. The default merge method is auto and it will default to the
radix method. The radix method will return the correct merge result regardless of duplicated rows
in the right frame. In addition, the radix method can perform merge even if you have string columns
in your frames. If there are duplicated rows in your rite frame, they will not be included if you use
the hash method. The hash method cannot perform merge if you have string columns in your left frame.
Hence, we consider the radix method superior to the hash method and is the default method to use.
:param H2OFrame other: The frame to merge to the current one. By default, must have at least one column in common with
this frame, and all columns in common are used as the merge key. If you want to use only a subset of the
columns in common, rename the other columns so the columns are unique in the merged result.
:param bool all_x: If True, include all rows from the left/self frame
:param bool all_y: If True, include all rows from the right/other frame
:param by_x: list of columns in the current frame to use as a merge key.
:param by_y: list of columns in the ``other`` frame to | python | {
"resource": ""
} |
q267152 | H2OFrame.relevel | test | def relevel(self, y):
"""
Reorder levels of an H2O factor for one single column of a H2O frame
The levels of a factor are reordered such that the reference level is at level 0, all remaining levels are
moved down as needed.
:param str y: The reference level | python | {
"resource": ""
} |
q267153 | H2OFrame.insert_missing_values | test | def insert_missing_values(self, fraction=0.1, seed=None):
"""
Insert missing values into the current frame, modifying it in-place.
Randomly replaces a user-specified fraction of entries in a H2O dataset with missing
values.
:param float fraction: A number between 0 and 1 indicating the fraction of entries to replace with missing.
:param int seed: The seed for the random number generator used to determine which values to make missing.
:returns: the original H2OFrame with missing values inserted.
"""
kwargs = {}
kwargs['dataset'] = self.frame_id # Eager; forces eval now for following | python | {
"resource": ""
} |
q267154 | H2OFrame.var | test | def var(self, y=None, na_rm=False, use=None):
"""
Compute the variance-covariance matrix of one or two H2OFrames.
:param H2OFrame y: If this parameter is given, then a covariance matrix between the columns of the target
frame and the columns of ``y`` is computed. If this parameter is not provided then the covariance matrix
of the target frame is returned. If target frame has just a single column, then return the scalar variance
instead of the matrix. Single rows are treated as single columns.
:param str use: A string indicating how to handle missing values. This could be one of the following:
- ``"everything"``: outputs NaNs whenever one of its contributing observations is missing
- ``"all.obs"``: presence of missing observations will throw an error
- ``"complete.obs"``: discards missing values along with all observations in their rows so that only
complete observations are used
:param bool na_rm: an alternative to ``use``: when this is True then default value for ``use`` is
``"everything"``; and if False then default ``use`` is ``"complete.obs"``. This parameter has no effect
if ``use`` is given explicitly.
:returns: An H2OFrame of the covariance matrix of the columns of this frame (if ``y`` is | python | {
"resource": ""
} |
q267155 | H2OFrame.cor | test | def cor(self, y=None, na_rm=False, use=None):
"""
Compute the correlation matrix of one or two H2OFrames.
:param H2OFrame y: If this parameter is provided, then compute correlation between the columns of ``y``
and the columns of the current frame. If this parameter is not given, then just compute the correlation
matrix for the columns of the current frame.
:param str use: A string indicating how to handle missing values. This could be one of the following:
- ``"everything"``: outputs NaNs whenever one of its contributing observations is missing
- ``"all.obs"``: presence of missing observations will throw an error
- ``"complete.obs"``: discards missing values along with all observations in their rows so that only
complete observations are used
:param bool na_rm: an alternative to ``use``: when this is True then default value for ``use`` is
``"everything"``; and if False then default ``use`` is ``"complete.obs"``. This parameter has no effect
if ``use`` is given explicitly.
:returns: An H2OFrame of the correlation matrix of the columns of this frame (if ``y`` is not given),
or with the columns of ``y`` (if ``y`` is given). However | python | {
"resource": ""
} |
q267156 | H2OFrame.distance | test | def distance(self, y, measure=None):
"""
Compute a pairwise distance measure between all rows of two numeric H2OFrames.
:param H2OFrame y: Frame containing queries (small)
:param str use: A string indicating what distance measure to use. Must be one of:
- ``"l1"``: Absolute distance (L1-norm, >=0)
- ``"l2"``: Euclidean distance (L2-norm, >=0)
- ``"cosine"``: Cosine similarity (-1...1)
- ``"cosine_sq"``: Squared Cosine similarity (0...1)
:examples:
>>>
>>> iris_h2o = h2o.import_file(path=pyunit_utils.locate("smalldata/iris/iris.csv"))
>>> references = iris_h2o[10:150,0:4
>>> queries = iris_h2o[0:10,0:4]
>>> A = references.distance(queries, "l1")
>>> B = references.distance(queries, | python | {
"resource": ""
} |
q267157 | H2OFrame.asfactor | test | def asfactor(self):
"""
Convert columns in the current frame to categoricals.
:returns: new H2OFrame with columns of the "enum" type.
"""
for colname in self.names:
t = self.types[colname]
if t not in {"bool", "int", "string", "enum"}:
raise H2OValueError("Only 'int' or 'string' are allowed for "
"asfactor(), got %s:%s " % (colname, t))
fr | python | {
"resource": ""
} |
q267158 | H2OFrame.strsplit | test | def strsplit(self, pattern):
"""
Split the strings in the target column on the given regular expression pattern.
:param str pattern: The split pattern.
:returns: H2OFrame containing columns of the split strings.
"""
| python | {
"resource": ""
} |
q267159 | H2OFrame.countmatches | test | def countmatches(self, pattern):
"""
For each string in the frame, count the occurrences of the provided pattern. If countmathces is applied to
a frame, all columns of the frame must be type string, otherwise, the returned frame will contain errors.
The pattern here is a plain string, not a regular expression. We will search for the occurrences of the
pattern as a substring in element of the frame. This function is applicable to frames containing only
string or categorical columns.
:param str pattern: The pattern to count matches on in each string. This can also be a list of strings,
in which case all of them will be searched for.
| python | {
"resource": ""
} |
q267160 | H2OFrame.substring | test | def substring(self, start_index, end_index=None):
"""
For each string, return a new string that is a substring of the original string.
If end_index is not specified, then the substring extends to the end of the original string. If the start_index
is longer than the length of the string, or is greater than or equal to the end_index, an empty string is
| python | {
"resource": ""
} |
q267161 | H2OFrame.lstrip | test | def lstrip(self, set=" "):
"""
Return a copy of the column with leading characters removed.
The set argument is a string specifying the set of characters to be removed.
If omitted, the set argument defaults to removing whitespace.
:param character set: The set of characters to lstrip from strings | python | {
"resource": ""
} |
q267162 | H2OFrame.entropy | test | def entropy(self):
"""
For each string compute its Shannon entropy, if the string is empty the entropy is 0.
:returns: an H2OFrame of Shannon entropies.
"""
| python | {
"resource": ""
} |
q267163 | H2OFrame.num_valid_substrings | test | def num_valid_substrings(self, path_to_words):
"""
For each string, find the count of all possible substrings with 2 characters or more that are contained in
the line-separated text file whose path is given.
:param str path_to_words: Path to file that contains a line-separated list of strings considered valid.
:returns: An H2OFrame with the number of substrings that are contained in the given word list.
| python | {
"resource": ""
} |
q267164 | H2OFrame.table | test | def table(self, data2=None, dense=True):
"""
Compute the counts of values appearing in a column, or co-occurence counts between two columns.
:param H2OFrame data2: An optional single column to aggregate counts by.
:param bool dense: If True (default) then use dense representation, which lists only non-zero counts,
1 combination per row. Set to False to expand counts across all combinations.
| python | {
"resource": ""
} |
q267165 | H2OFrame.hist | test | def hist(self, breaks="sturges", plot=True, **kwargs):
"""
Compute a histogram over a numeric column.
:param breaks: Can be one of ``"sturges"``, ``"rice"``, ``"sqrt"``, ``"doane"``, ``"fd"``, ``"scott"``;
or a single number for the number of breaks; or a list containing the split points, e.g:
``[-50, 213.2123, 9324834]``. If breaks is "fd", the MAD is used over the IQR in computing bin width.
:param bool plot: If True (default), then a plot will be generated using ``matplotlib``.
:returns: If ``plot`` is False, return H2OFrame with these columns: breaks, counts, mids_true,
mids, and density; otherwise this method draws a plot and returns nothing.
"""
server = kwargs.pop("server") if "server" in kwargs else False
assert_is_type(breaks, int, [numeric], Enum("sturges", "rice", "sqrt", "doane", "fd", "scott"))
assert_is_type(plot, bool)
assert_is_type(server, bool)
if | python | {
"resource": ""
} |
q267166 | H2OFrame.isax | test | def isax(self, num_words, max_cardinality, optimize_card=False, **kwargs):
"""
Compute the iSAX index for DataFrame which is assumed to be numeric time series data.
References:
- http://www.cs.ucr.edu/~eamonn/SAX.pdf
- http://www.cs.ucr.edu/~eamonn/iSAX_2.0.pdf
:param int num_words: Number of iSAX words for the timeseries, i.e. granularity along the time series
:param int max_cardinality: Maximum cardinality of the iSAX word. Each word can have less than the max
:param bool optimized_card: An optimization flag that will find the max cardinality regardless of what is
passed in for ``max_cardinality``.
:returns: An H2OFrame with the name of time series, string | python | {
"resource": ""
} |
q267167 | H2OFrame.sub | test | def sub(self, pattern, replacement, ignore_case=False):
"""
Substitute the first occurrence of pattern in a string with replacement.
:param str pattern: A regular expression.
:param str replacement: A replacement | python | {
"resource": ""
} |
q267168 | H2OFrame.toupper | test | def toupper(self):
"""
Translate characters from lower to upper case for a particular column.
:returns: new H2OFrame with all strings in the current frame converted to the uppercase.
| python | {
"resource": ""
} |
q267169 | H2OFrame.grep | test | def grep(self,pattern, ignore_case = False, invert = False, output_logical = False):
"""
Searches for matches to argument `pattern` within each element
of a string column.
Default behavior is to return indices of the elements matching the pattern. Parameter
`output_logical` can be used to return a logical vector indicating if the element matches
the pattern (1) or not (0).
:param str pattern: A character string containing a regular expression.
:param bool ignore_case: If True, then case is ignored during matching.
:param bool invert: If True, then identify elements that do not match the pattern.
:param | python | {
"resource": ""
} |
q267170 | H2OFrame.na_omit | test | def na_omit(self):
"""
Remove rows with NAs from the H2OFrame.
:returns: new H2OFrame with all rows from the original frame containing any NAs removed.
"""
| python | {
"resource": ""
} |
q267171 | H2OFrame.difflag1 | test | def difflag1(self):
"""
Conduct a diff-1 transform on a numeric frame column.
:returns: an H2OFrame where each element is equal to the corresponding element in the source
frame minus the previous-row element in the same frame.
"""
if self.ncols > 1:
| python | {
"resource": ""
} |
q267172 | H2OFrame.isna | test | def isna(self):
"""
For each element in an H2OFrame, determine if it is NA or not.
:returns: an H2OFrame of 1s and 0s, where 1s mean the values were NAs.
"""
fr = H2OFrame._expr(expr=ExprNode("is.na", self))
fr._ex._cache.nrows = self._ex._cache.nrows
fr._ex._cache.ncols = self._ex._cache.ncols
if self._ex._cache.names:
| python | {
"resource": ""
} |
q267173 | H2OFrame.minute | test | def minute(self):
"""
Extract the "minute" part from a date column.
:returns: a single-column H2OFrame containing the "minute" part from the source frame. | python | {
"resource": ""
} |
q267174 | H2OFrame.runif | test | def runif(self, seed=None):
"""
Generate a column of random numbers drawn from a uniform distribution [0,1) and
having the same data layout as the source frame.
:param int seed: seed for the random number generator.
:returns: Single-column H2OFrame filled with doubles sampled uniformly from [0,1).
"""
| python | {
"resource": ""
} |
q267175 | H2OFrame.stratified_split | test | def stratified_split(self, test_frac=0.2, seed=-1):
"""
Construct a column that can be used to perform a random stratified split.
:param float test_frac: The fraction of rows that will belong to the "test".
:param int seed: The seed for the random number generator.
:returns: an H2OFrame having single categorical column with two levels: ``"train"`` and ``"test"``.
:examples:
>>> stratsplit = df["y"].stratified_split(test_frac=0.3, seed=12349453)
>>> train = df[stratsplit=="train"]
>>> test = df[stratsplit=="test"]
>>>
>>> # check that the distributions among the initial | python | {
"resource": ""
} |
q267176 | H2OFrame.cut | test | def cut(self, breaks, labels=None, include_lowest=False, right=True, dig_lab=3):
"""
Cut a numeric vector into categorical "buckets".
This method is only applicable to a single-column numeric frame.
:param List[float] breaks: The cut points in the numeric vector.
:param List[str] labels: Labels for categorical levels produced. Defaults to set notation of
intervals defined by the breaks.
:param bool include_lowest: By default, cuts are defined as intervals ``(lo, hi]``. If this parameter
is True, then the interval becomes ``[lo, hi]``.
:param bool right: Include the high value: ``(lo, hi]``. If False, get ``(lo, hi)``.
:param int dig_lab: Number of digits following the decimal point to consider.
| python | {
"resource": ""
} |
q267177 | H2OFrame.idxmax | test | def idxmax(self,skipna=True, axis=0):
"""
Get the index of the max value in a column or row
:param bool skipna: If True (default), then NAs are ignored during the search. Otherwise presence
of NAs renders the entire result NA.
:param int axis: Direction of finding the max index. If 0 (default), then the max index is searched columnwise, and the
result is a frame with 1 row and number of columns as in the original frame. If 1, then the max index is searched
rowwise and the result is a frame with 1 column, and number of rows equal to the number of rows | python | {
"resource": ""
} |
q267178 | H2OFrame.apply | test | def apply(self, fun=None, axis=0):
"""
Apply a lambda expression to an H2OFrame.
:param fun: a lambda expression to be applied per row or per column.
:param axis: 0 = apply to each column; 1 = apply to each row
:returns: a new H2OFrame with the results of applying ``fun`` to the current frame.
"""
from .astfun import lambda_to_expr
| python | {
"resource": ""
} |
q267179 | parse_text | test | def parse_text(text):
"""Parse code from a string of text."""
assert isinstance(text, _str_type), "`text` parameter should be a string, got %r" % type(text)
gen = iter(text.splitlines(True)) # True = keep | python | {
"resource": ""
} |
q267180 | parse_file | test | def parse_file(filename):
"""Parse the provided file, and return Code object."""
assert isinstance(filename, _str_type), | python | {
"resource": ""
} |
q267181 | Token.move | test | def move(self, drow, dcol=0):
"""Move the token by `drow` rows and `dcol` columns."""
self._start_row += drow
| python | {
"resource": ""
} |
q267182 | ParsedBase.unparse | test | def unparse(self):
"""Convert the parsed representation back into the source code."""
| python | {
"resource": ""
} |
q267183 | H2OClusteringModel.size | test | def size(self, train=False, valid=False, xval=False):
"""
Get the sizes of each cluster.
If all are False (default), then return the training metric value.
If more than one options is set to True, then return a dictionary of metrics where
the keys are "train", "valid", and "xval".
:param bool train: If True, return the cluster sizes for the training | python | {
"resource": ""
} |
q267184 | H2OClusteringModel.centers | test | def centers(self):
"""The centers for the KMeans model."""
o = self._model_json["output"]
cvals = o["centers"].cell_values
| python | {
"resource": ""
} |
q267185 | H2OClusteringModel.centers_std | test | def centers_std(self):
"""The standardized centers for the kmeans model."""
o = self._model_json["output"]
cvals = o["centers_std"].cell_values
centers_std | python | {
"resource": ""
} |
q267186 | connect | test | def connect(server=None, url=None, ip=None, port=None, https=None, verify_ssl_certificates=None, auth=None,
proxy=None, cookies=None, verbose=True, config=None):
"""
Connect to an existing H2O server, remote or local.
There are two ways to connect to a server: either pass a `server` parameter containing an instance of
an H2OLocalServer, or specify `ip` and `port` of the server that you want to connect to.
:param server: An H2OLocalServer instance to connect to (optional).
:param url: Full URL of the server to connect to (can be used instead of `ip` + `port` + `https`).
:param ip: The ip address (or host name) of the server where H2O is running.
:param port: Port number that H2O service is listening to.
:param https: Set to True to connect via https:// instead of http://.
:param verify_ssl_certificates: When using https, setting this to False will disable SSL certificates verification.
:param auth: Either a (username, password) pair for basic authentication, an instance of h2o.auth.SpnegoAuth
or one of the requests.auth authenticator objects.
:param proxy: Proxy server address.
| python | {
"resource": ""
} |
q267187 | api | test | def api(endpoint, data=None, json=None, filename=None, save_to=None):
"""
Perform a REST API request to a previously connected server.
This function is mostly for internal purposes, but may occasionally be useful for direct access to
the backend H2O server. It has same parameters as :meth:`H2OConnection.request | python | {
"resource": ""
} |
q267188 | version_check | test | def version_check():
"""Used to verify that h2o-python module and the H2O server are compatible with each other."""
from .__init__ import __version__ as ver_pkg
ci = h2oconn.cluster
if not ci:
raise H2OConnectionError("Connection not initialized. Did you run h2o.connect()?")
ver_h2o = ci.version
if ver_pkg == "SUBST_PROJECT_VERSION": ver_pkg = "UNKNOWN"
if str(ver_h2o) != str(ver_pkg):
branch_name_h2o = ci.branch_name
build_number_h2o = ci.build_number
if build_number_h2o is None or build_number_h2o == "unknown":
raise H2OConnectionError(
"Version mismatch. H2O is version {0}, but the h2o-python package is version {1}. "
"Upgrade H2O and h2o-Python to latest stable version - "
"http://h2o-release.s3.amazonaws.com/h2o/latest_stable.html"
"".format(ver_h2o, ver_pkg))
elif build_number_h2o == "99999":
raise H2OConnectionError(
"Version mismatch. H2O is version {0}, but the h2o-python package is version {1}. "
"This is a developer build, please contact your developer."
"".format(ver_h2o, ver_pkg)) | python | {
"resource": ""
} |
q267189 | lazy_import | test | def lazy_import(path, pattern=None):
"""
Import a single file or collection of files.
:param path: A path to a data file (remote or local).
:param pattern: Character string containing a regular expression to match file(s) in the folder.
:returns: either a :class:`H2OFrame` with the content of the provided file, or a list of such frames if
importing multiple | python | {
"resource": ""
} |
q267190 | upload_file | test | def upload_file(path, destination_frame=None, header=0, sep=None, col_names=None, col_types=None,
na_strings=None, skipped_columns=None):
"""
Upload a dataset from the provided local path to the H2O cluster.
Does a single-threaded push to H2O. Also see :meth:`import_file`.
:param path: A path specifying the location of the data to upload.
:param destination_frame: The unique hex key assigned to the imported file. If none is given, a key will
be automatically generated.
:param header: -1 means the first line is data, 0 means guess, 1 means first line is header.
:param sep: The field separator character. Values on each line of the file are separated by
this character. If not provided, the parser will automatically detect the separator.
:param col_names: A list of column names for the file.
:param col_types: A list of types or a dictionary of column names to types to specify whether columns
should be forced to a certain type upon import parsing. If a list, the types for elements that are
one will be guessed. The possible types a column may have are:
- "unknown" - this will force the column to be parsed as all NA
- "uuid" - the values in the column must be true UUID or will be parsed as NA
- "string" - force the column to be parsed as a string
- "numeric" - force the column to be parsed as numeric. H2O will handle the compression of the numeric
data in the optimal manner.
- "enum" - force the column to be parsed as a categorical column.
- "time" - force the column to be parsed as a time column. H2O will attempt to parse the following
list of date time formats: (date) "yyyy-MM-dd", "yyyy MM dd", "dd-MMM-yy", "dd MMM yy", (time)
"HH:mm:ss", "HH:mm:ss:SSS", "HH:mm:ss:SSSnnnnnn", | python | {
"resource": ""
} |
q267191 | import_file | test | def import_file(path=None, destination_frame=None, parse=True, header=0, sep=None, col_names=None, col_types=None,
na_strings=None, pattern=None, skipped_columns=None, custom_non_data_line_markers = None):
"""
Import a dataset that is already on the cluster.
The path to the data must be a valid path for each node in the H2O cluster. If some node in the H2O cluster
cannot see the file, then an exception will be thrown by the H2O cluster. Does a parallel/distributed
multi-threaded pull of the data. The main difference between this method and :func:`upload_file` is that
the latter works with local files, whereas this method imports remote files (i.e. files local to the server).
If you running H2O server on your own maching, then both methods behave the same.
:param path: path(s) specifying the location of the data to import or a path to a directory of files to import
:param destination_frame: The unique hex key assigned to the imported file. If none is given, a key will be
automatically generated.
:param parse: If True, the file should be parsed after import. If False, then a list is returned containing the file path.
:param header: -1 means the first line is data, 0 means guess, 1 means first line is header.
:param sep: The field separator character. Values on each line of the file are separated by
this character. If not provided, the parser will automatically detect the separator.
:param col_names: A list of column names for the file.
:param col_types: A list of types or a dictionary of column names to types to specify whether columns
should be forced to a certain type upon import parsing. If a list, the types for elements that are
one will be guessed. The possible types a column may have are:
- "unknown" - this will force the column to be parsed as all NA
- "uuid" - the values in the column must be true UUID or will be parsed as NA
- "string" - force the column to be parsed as a string
- "numeric" - force the column to be parsed as numeric. H2O will handle the compression of the numeric
data in the optimal manner.
- "enum" - force the column to be parsed as a categorical column.
- "time" - force the column to be parsed as a time column. H2O will attempt to parse the following
list of date time formats: (date) "yyyy-MM-dd", "yyyy MM dd", "dd-MMM-yy", "dd MMM yy", (time)
"HH:mm:ss", "HH:mm:ss:SSS", "HH:mm:ss:SSSnnnnnn", "HH.mm.ss" "HH.mm.ss.SSS", "HH.mm.ss.SSSnnnnnn".
Times can also contain "AM" or "PM".
:param na_strings: A list of strings, or a list of lists of strings (one list per column), or a dictionary
of column names to strings which are to be interpreted as missing values.
:param pattern: Character string containing a regular expression to match file(s) in the folder if `path` is a
directory.
:param skipped_columns: an integer list of column indices to skip and not parsed into the final frame from the import file.
:param custom_non_data_line_markers: If a line in imported file starts with any character in given string it will NOT be imported. Empty string means all lines are | python | {
"resource": ""
} |
q267192 | import_hive_table | test | def import_hive_table(database=None, table=None, partitions=None, allow_multi_format=False):
"""
Import Hive table to H2OFrame in memory.
Make sure to start H2O with Hive on classpath. Uses hive-site.xml on classpath to connect to Hive.
:param database: Name of Hive database (default database will be used by default)
:param table: name of Hive table to import
:param partitions: a list of lists of strings - partition key column values of partitions you want to import.
:param allow_multi_format: enable import of | python | {
"resource": ""
} |
q267193 | import_sql_table | test | def import_sql_table(connection_url, table, username, password, columns=None, optimize=True, fetch_mode=None):
"""
Import SQL table to H2OFrame in memory.
Assumes that the SQL table is not being updated and is stable.
Runs multiple SELECT SQL queries concurrently for parallel ingestion.
Be sure to start the h2o.jar in the terminal with your downloaded JDBC driver in the classpath::
java -cp <path_to_h2o_jar>:<path_to_jdbc_driver_jar> water.H2OApp
Also see :func:`import_sql_select`.
Currently supported SQL databases are MySQL, PostgreSQL, MariaDB, Hive, Oracle and Microsoft SQL.
:param connection_url: URL of the SQL database connection as specified by the Java Database Connectivity (JDBC)
Driver. For example, "jdbc:mysql://localhost:3306/menagerie?&useSSL=false"
:param table: name of SQL table
:param columns: a list of column names to import from SQL table. Default is to import all columns.
:param username: username for SQL server
:param password: password for SQL server
:param optimize: DEPRECATED. Ignored - use fetch_mode instead. Optimize import of SQL table for faster imports.
:param fetch_mode: Set to DISTRIBUTED to enable distributed import. Set to SINGLE to force a sequential read by a single node
from the database.
:returns: an :class:`H2OFrame` containing data of the specified SQL table.
:examples:
>>> conn_url = "jdbc:mysql://172.16.2.178:3306/ingestSQL?&useSSL=false"
>>> table = "citibike20k"
>>> username = "root"
| python | {
"resource": ""
} |
q267194 | import_sql_select | test | def import_sql_select(connection_url, select_query, username, password, optimize=True,
use_temp_table=None, temp_table_name=None, fetch_mode=None):
"""
Import the SQL table that is the result of the specified SQL query to H2OFrame in memory.
Creates a temporary SQL table from the specified sql_query.
Runs multiple SELECT SQL queries on the temporary table concurrently for parallel ingestion, then drops the table.
Be sure to start the h2o.jar in the terminal with your downloaded JDBC driver in the classpath::
java -cp <path_to_h2o_jar>:<path_to_jdbc_driver_jar> water.H2OApp
Also see h2o.import_sql_table. Currently supported SQL databases are MySQL, PostgreSQL, MariaDB, Hive, Oracle
and Microsoft SQL Server.
:param connection_url: URL of the SQL database connection as specified by the Java Database Connectivity (JDBC)
Driver. For example, "jdbc:mysql://localhost:3306/menagerie?&useSSL=false"
:param select_query: SQL query starting with `SELECT` that returns rows from one or more database tables.
:param username: username for SQL server
:param password: password for SQL server
:param optimize: DEPRECATED. Ignored - use fetch_mode instead. Optimize import of SQL table for faster imports.
:param use_temp_table: whether a temporary table should be created from select_query
:param temp_table_name: name of temporary table to be created from select_query
:param fetch_mode: Set to DISTRIBUTED to enable distributed import. Set to SINGLE to force a sequential read by a single node
from the database.
:returns: an :class:`H2OFrame` containing data of the specified SQL query.
:examples:
>>> conn_url = "jdbc:mysql://172.16.2.178:3306/ingestSQL?&useSSL=false"
>>> select_query = "SELECT | python | {
"resource": ""
} |
q267195 | parse_raw | test | def parse_raw(setup, id=None, first_line_is_header=0):
"""
Parse dataset using the parse setup structure.
:param setup: Result of ``h2o.parse_setup()``
:param id: an id for the frame.
:param first_line_is_header: -1, 0, 1 if the first line is to be used as the header
:returns: an :class:`H2OFrame` object.
"""
assert_is_type(setup, dict)
assert_is_type(id, str, None)
assert_is_type(first_line_is_header, -1, 0, 1)
check_frame_id(id)
| python | {
"resource": ""
} |
q267196 | deep_copy | test | def deep_copy(data, xid):
"""
Create a deep clone of the frame ``data``.
:param data: an H2OFrame to be cloned
:param xid: (internal) id to be assigned to the new frame.
:returns: new :class:`H2OFrame` which is the clone of the passed frame.
"""
assert_is_type(data, H2OFrame)
assert_is_type(xid, str)
assert_satisfies(xid, xid != data.frame_id)
check_frame_id(xid)
| python | {
"resource": ""
} |
q267197 | get_model | test | def get_model(model_id):
"""
Load a model from the server.
:param model_id: The model identification in H2O
:returns: Model object, a subclass of H2OEstimator
"""
assert_is_type(model_id, str)
model_json = api("GET /3/Models/%s" % model_id)["models"][0]
algo = model_json["algo"]
if algo == "svd": m = H2OSVD()
elif algo == "pca": m = H2OPrincipalComponentAnalysisEstimator()
elif algo == "drf": m = H2ORandomForestEstimator()
elif algo == "naivebayes": m = H2ONaiveBayesEstimator()
elif algo == "kmeans": m = H2OKMeansEstimator()
elif algo == "glrm": m = H2OGeneralizedLowRankEstimator()
elif algo == "glm": m = H2OGeneralizedLinearEstimator()
elif algo == "gbm": m = H2OGradientBoostingEstimator()
elif algo == "deepwater": m = H2ODeepWaterEstimator() | python | {
"resource": ""
} |
q267198 | get_grid | test | def get_grid(grid_id):
"""
Return the specified grid.
:param grid_id: The grid identification in h2o
:returns: an :class:`H2OGridSearch` instance.
"""
assert_is_type(grid_id, str)
grid_json = api("GET /99/Grids/%s" % grid_id)
models = [get_model(key["name"]) for key in grid_json["model_ids"]]
# get first model returned in list of models from grid search to get model class (binomial, multinomial, etc)
first_model_json = api("GET /3/Models/%s" % grid_json["model_ids"][0]["name"])["models"][0]
| python | {
"resource": ""
} |
q267199 | get_frame | test | def get_frame(frame_id, **kwargs):
"""
Obtain a handle to the frame in H2O with the frame_id key.
:param str frame_id: id of the frame to retrieve.
:returns: an :class:`H2OFrame` object
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.