Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export h2o.shallow_copy #16589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion h2o-py/h2o/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from h2o.h2o import (connect, init, api, connection, resume,
lazy_import, upload_file, import_file, import_sql_table, import_sql_select, import_hive_table,
parse_setup, parse_raw, assign, deep_copy, models, get_model, get_grid, get_frame,
parse_setup, parse_raw, assign, deep_copy, shallow_copy, models, get_model, get_grid, get_frame,
show_progress, no_progress, enable_expr_optimizations, is_expr_optimizations_enabled,
log_and_echo, remove, remove_all, rapids,
ls, frame, frames, create_frame, load_frame,
Expand Down
2 changes: 1 addition & 1 deletion h2o-py/h2o/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, python_obj=None, destination_frame=None, header=0, separator=

self._is_frame = True # Indicate that this is an actual frame, allowing typechecks to be made
if isinstance(python_obj, H2OFrame):
sc = h2o.h2o.shallow_copy(python_obj, destination_frame)
sc = h2o.shallow_copy(python_obj, destination_frame)
if skipped_columns:
sc = sc.drop(skipped_columns)
if column_names:
Expand Down
16 changes: 15 additions & 1 deletion h2o-py/h2o/h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,21 @@ def deep_copy(data, xid):
assign(duplicate, xid)
return duplicate

def shallow_copy(data, xid):
def shallow_copy(data, xid=None):
"""
Create a shallow 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.

:examples:

>>> training_data = h2o.import_file("http://s3.amazonaws.com/h2o-public-test-data/smalldata/prostate/prostate.csv.zip")
>>> new_name = "new_frame"
>>> training_copy = h2o.shallow_copy(training_data, new_name)
>>> training_copy
"""
assert_is_type(data, H2OFrame)
assert_is_type(xid, None, str)
duplicate = H2OFrame._expr(expr=ExprNode("cols_py", data, slice(data.ncols)))
Expand Down