xgt.VertexFrame¶
-
class
xgt.
VertexFrame
(conn, name, schema, key, error_frame_name)¶ VertexFrame object represents a collection of vertices 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_vertex_frame(), Connection.get_vertex_frames() and Connection.create_vertex_frame().
Each vertex in a VertexFrame shares the same properties, described in VertexFrame.schema. Each vertex in a VertexFrame is uniquely identified by the property listed in VertexFrame.key.
- Parameters
conn (Connection) – An open connection to an xGT server.
name (str) – Name of vertex frame.
schema (list of pairs) – List of pairs associating property names with xGT data types. Each vertex in the VertexFrame will have these properties.
key (str) – The property name used to uniquely identify vertices in the graph. This is the name of one of the properties from the schema and must be unique for each vertex in the frame.
error_frame_name (str) – Name of the frame created to store errors encountered while loading data. (internal)
Examples
>>> import xgt >>> conn = xgt.Connection() >>> v1 = conn.create_vertex_frame( ... name = 'People', ... schema = [['id', xgt.INT], ... ['name', xgt.TEXT]], ... key = 'id') >>> v2 = conn.get_vertex_frame('Companies') # An existing vertex frame >>> print(v1.name, v2.name)
-
__init__
(conn, name, schema, key, error_frame_name)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(conn, name, schema, key, …)Initialize self.
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 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
Name of the error table this frame will produce on errors.
Gets the property name that uniquely identifies vertices of this type.
Name of the table.
Gets the number of vertices in the VertexFrame.
Gets the number of vertices in the VertexFrame.
Gets the property names and types of the table.
-
property
error_frame_name
¶ Name of the error table 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
-
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.
-
property
key
¶ Gets the property name that uniquely identifies vertices of this type.
- Type
str
-
load
(paths, headerMode='none')¶ 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>’
xgtd computer:
’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.
-
property
name
¶ Name of the table.
- Type
str
-
property
num_rows
¶ Gets the number of vertices in the VertexFrame.
- Type
int
-
property
num_vertices
¶ Gets the number of vertices in the VertexFrame.
- 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:
’<path to csv file>’ ‘xgt://<path to csv file>’
xgtd computer:
’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.
-
property
schema
¶ Gets the property names and types of the table.
- Type
list of lists