7.3.2. xgt.EdgeFrame

class xgt.EdgeFrame(conn, name, schema, source, target, source_key, target_key, error_frame_name)

EdgeFrame object represents a collection of edges held on the xGT server; it can be used to retrieve information about them and should not be instantiated directly by the user. Methods that return this object: Connection.get_edge_frame(), Connection.get_edge_frames() and Connection.create_edge_frame(). Each edge in an EdgeFrame shares the same properties, described in EdgeFrame.schema.

The source vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This name of this VertexFrame is given by EdgeFrame.source_name. The targe vertex of each edge in an EdgeFrame must belong to the same VertexFrame. This name of this VertexFrame is given by EdgeFrame.target_name.

For each edge in the EdgeFrame, its source vertex is identified by the edge property name given by EdgeFrame.source_key, which is be one of the properties listed in the schema. The edge target vertex is identified by the property name given by EdgeFrame.target_key.

Parameters
  • conn (Connection) – An open connection to an xGT server.

  • name (str) – Fully qualified name of the edge frame, including the namespace.

  • schema (list of pairs) – List of pairs associating property names with xGT data types. Each edge in the EdgeFrame will have these properties.

  • source (str or VertexFrame) – The name of a VertexFrame or a VertexFrame object. The source vertex of each edge in this EdgeFrame will belong to this VertexFrame.

  • target (str or VertexFrame) – The name of a VertexFrame or a VertexFrame object. The target vertex of each edge in this EdgeFrame will belong to this VertexFrame.

  • source_key (str) – The edge property name that identifies the source vertex of an edge. This is one of the properties from the schema.

  • target_key (str) – The edge property name that identifies the target vertex of an edge. This is one of the properties from the schema.

  • error_frame_name (str) – Name of the frame created to store errors encountered while loading data. (internal)

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> e1 = conn.create_edge_frame(
...        name = 'career__WorksFor',
...        schema = [['srcid', xgt.INT],
...                  ['role', xgt.TEXT],
...                  ['trgid', xgt.INT]],
...        source = 'career__People',
...        target = 'career__Companies',
...        source_key = 'srcid',
...        target_key = 'trgid')
>>> e2 = conn.get_edge_frame('career__RelatedTo') # An existing edge frame
>>> print(e1.name, e2.name)
__init__(conn, name, schema, source, target, source_key, target_key, error_frame_name)

Constructor for EdgeFrame. Called when EdgeFrame is created.

Methods

__init__(conn, name, schema, source, target, …)

Constructor for EdgeFrame.

get_data([offset, length])

Returns frame data starting at a given offset and spanning a given length.

get_data_pandas([offset, length])

Returns a Pandas DataFrame containing frame data starting at a given offset and spanning a given length.

insert(data)

Inserts data rows.

load(paths[, headerMode, record_history])

Loads data from one or more CSV files specified in the list of paths.

save(path[, offset, length, headers, …])

Writes the rows from the frame to a CSV file in the path and the computer indicated by the path.

Attributes

connection

The connection used when constructing the frame.

error_frame_name

Name of the error table frame this frame will produce on errors.

name

Name of the frame.

num_edges

Gets the number of edges in the EdgeFrame.

num_rows

Gets the number of rows in the frame.

schema

Gets the property names and types of the frame.

source_key

The edge property name that identifies the source vertex of an edge.

source_name

Gets the name of the source vertex frame.

target_key

The edge property name that identifies the target vertex of an edge.

target_name

Gets the name of the target vertex frame.

property connection

The connection used when constructing the frame.

Type

Connection object

property error_frame_name

Name of the error table frame this frame will produce on errors.

Type

str

get_data(offset=0, length=None)

Returns frame data starting at a given offset and spanning a given length.

Parameters
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.

  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.

Returns

Return type

list of lists

Raises
get_data_pandas(offset=0, length=None)

Returns a Pandas DataFrame containing frame data starting at a given offset and spanning a given length.

Parameters
  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.

  • length (int) – Maximum number of rows to be retrieved starting from the row indicated by offset. A value of ‘None’ means ‘all rows’ on and after the offset. Optional. Default=None.

Returns

Return type

Pandas DataFrame

Raises
insert(data)

Inserts data rows. The properties of the new data must match the schema in both order and type.

Parameters

data (list or Pandas dataframe) – Data represented by a list of lists of data items or by a Pandas Dataframe.

Raises
  • XgtValueError – If errors are present in the data to insert. If the ingest error frame is non-empty due to errors in previous data uploads.

  • XgtNameError – If the frame does not exist on the server.

  • XgtSecurityError – If the user does not have required permissions for this action.

  • XgtTransactionError – If a conflict with another transaction occurs.

load(paths, headerMode='none', record_history=True)

Loads data from one or more CSV files specified in the list of paths. Each path may have its own protocol as described below.

Parameters
  • paths (list) –

    Paths to the CSV files.

    Syntax for one CSV file path

    Resource type

    Path syntax

    local to Python:

    ’<path to csv file>’ ‘xgt://<path to csv file>’

    xGT server:

    ’xgtd://<path to csv file>’

    AWS s3:

    ’s3://<path to csv file>’

    https site:

    https://<path to csv file>’

    http site:

    http://<path to csv file>’

    ftps server:

    ’ftps://<path to csv file>’

    ftp server:

    ftp://<path to csv file>’

  • headerMode (str) –

    Indicates if the files contain headers:
    • HeaderMode.NONE

    • HeaderMode.IGNORE

    • HeaderMode.NORMAL

    • HeaderMode.STRICT

    Optional. Default=HeaderMode.NONE.

  • record_history (bool) – If true, records the history of the job. (since version 1.4.0)

Returns

A Job object representing the job that has executed the load.

Return type

Job

Raises
  • XgtValueError – If errors are present in the data to insert. If the ingest error frame is non-empty due to errors in previous data uploads.

  • XgtIOError – If a file specified cannot be opened.

  • XgtNameError – If the frame does not exist on the server.

  • XgtSecurityError – If the user does not have required permissions for this action.

  • XgtTransactionError – If a conflict with another transaction occurs.

property name

Name of the frame.

Type

str

property num_edges

Gets the number of edges in the EdgeFrame.

Type

int

property num_rows

Gets the number of rows in the frame.

Type

int

save(path, offset=0, length=None, headers=False, record_history=True)

Writes the rows from the frame to a CSV file in the path and the computer indicated by the path.

Parameters
  • path (str) –

    Path to the CSV file.

    Syntax for one CSV file path

    Resource type

    Path syntax

    local to Python:

    ’<path to csv file>’ ‘xgt://<path to csv file>’

    xGT server:

    ’xgtd://<path to csv file>’

  • offset (int) – Position (index) of the first row to be retrieved. Optional. Default=0.

  • length (int) – Maximum number of rows to be retrieved. Optional. Default=None.

  • headers (boolean) – Indicates if headers should be added. Optional. Default=False.

  • record_history (bool) – If true, records the history of the job. (since version 1.4.0)

Returns

A Job object representing the job that has executed the save.

Return type

Job

Raises
property schema

Gets the property names and types of the frame.

Type

list of lists

property source_key

The edge property name that identifies the source vertex of an edge.

Type

str

property source_name

Gets the name of the source vertex frame.

Type

str

property target_key

The edge property name that identifies the target vertex of an edge.

Type

str

property target_name

Gets the name of the target vertex frame.

Type

str