xgt.EdgeFrame

class xgt.EdgeFrame(conn, obj)

EdgeFrame objects represent a collection of edges held on the xGT server and can be used to retrieve information about them. These objects are returned by the Connection.get_edge_frame() method or by the Connection.create_edge_frame() method. Edge 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.
  • obj (json) – Internal edge structure expressed in JSON objects.

Examples

>>> import xgt
>>> conn = xgt.Connection()
>>> e1 = conn.create_edge_frame(
...          name = 'WorksFor',
...          schema = [['srcid', xgt.INT],
...                    ['role', xgt.TEXT],
...                    ['trgid', xgt.INT]],
...          source = 'Person',
...          target = 'Company',
...          source_key = 'srcid',
...          target_key = 'trgid')
>>> e2 = conn.get_edge_frame('RelatedTo') #RelatedTo is an existing edge type
>>> print(e1.name)
__init__(conn, obj)

x.__init__(…) initializes x; see help(type(x)) for signature

Methods

__init__(conn, obj) x.__init__(…) initializes x; see help(type(x)) for signature
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]) Loads data from a CSV file in the path and the computer indicated by the path.
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

name Name of the edge type.
num_edges Gets the number of edges of the edge type.
num_rows Gets the number of rows of the table.
schema Gets the property names and types of the edge type.
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.
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

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

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.
load(paths, headerMode=0)

Loads data from a CSV file in the path and the computer indicated by the path.

Parameters:
  • paths (list) –

    Paths to the CSV files.

    Syntax for one CSV file path
    Resource type Path syntax
    local to python: ’<absolute path to csv file>’
    xgtd computer: ’xgtd://<absolute path to csv file>’
    AWS s3: ’s3://<absolute path to csv file>’
    https site: https://<absolute path to csv file>’
    http site: http://<absolute path to csv file>’
    ftps server: ’ftps://<absolute path to csv file>’
  • headerMode (str) –
    Indicates if the files contain headers:
    • HeaderMode.NONE
    • HeaderMode.IGNORE
    • HeaderMode.NORMAL
    • HeaderMode.STRICT

    Optional. Default=HeaderMode.NONE.

name

Name of the edge type.

Type:str
num_edges

Gets the number of edges of the edge type.

Type:int
num_rows

Gets the number of rows of the table.

Type:int
save(path, offset=0, length=None, headers=False)

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: ’<absolute path to csv file>’
    xgtd computer: ’xgtd://<absolute path to csv file>’
    AWS s3: ’s3://<absolute path to csv file>’
    https site: https://<absolute path to csv file>’
    http site: http://<absolute path to csv file>’
    ftps server: ’ftps://<absolute 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.
schema

Gets the property names and types of the edge type.

Type:list of lists
source_key

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

Type:str
source_name

Gets the name of the source vertex frame.

Type:str
target_key

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

Type:str
target_name

Gets the name of the target vertex frame.

Type:str