Frames

PgxFrame and other classes related to frames.

class pypgx.api.frames.PgxCsvFrameReader(java_pgx_csv_frame_reader)

Bases: object

Class for reading PgxFrame objects from CSV files.

auto_detect_columns(auto_detect: bool) pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader

Enable or disable the autodetection of columns from the table.

Executing this function clears the currently loaded column descriptors.

Parameters

auto_detect (bool) – True if the columns should be autodetected, False otherwise

Returns

self

clear_columns() None

Clear the current configuration of which columns should be loaded and how.

Returns

None

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader

Set the columns to be loaded from their columnDescriptors.

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

self

load(uris: str) pypgx.api.frames._pgx_frame.PgxFrame

Load a PgxFrame from the provided URIs.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

load_async(uris: str)

Load a PgxFrame from the provided URIs.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

name(frame_name: str) pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader

Set the frame name.

Parameters

frame_name (str) – New name for the PgxFrame

Returns

self

separator(sep: str) pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader

Set the separator for CSV parsing to sep.

Parameters

sep – char denoting the separator

Returns

self

class pypgx.api.frames.PgxCsvFrameStorer(java_pgx_csv_frame_storer)

Bases: object

Class for configuring the storing operation of a PgxFrame to a CSV file and then triggering it.

clear_columns() None

Clear columns

Returns

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set columns

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

name(frame_name: str) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set the frame name.

Parameters

frame_name – frame name.

Returns

this storer

overwrite(overwrite_bool: bool) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set overwrite

Parameters

overwrite_bool – denotes if the table should be overwritten.

Returns

partition_extension(file_extension: str) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set the fileExtension of the created CSV files.

Parameters

file_extension – string denoting the file extension for the created files.

Returns

this storer

partitions(num_partitions: int) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set the number of files to be created.

Parameters

num_partitions – number of partitions created.

Returns

this storer

separator(sep: str) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set the separator for CSV file to sep.

Parameters

sep – char denoting the separator

Returns

self

store() None

Store PgxFrame

Returns

PgxFrame instance

store_async()

Store PgxFrame

Returns

PgxFrame instance

table_name(table_name: str) pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Set the table name in the database.

Parameters

table_name – nodes table name.

Returns

this storer

class pypgx.api.frames.PgxDbFrameReader(java_pgx_db_frame_reader)

Bases: object

Class for reading PgxFrame objects from a database.

auto_detect_columns(auto_detect: bool) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Enable or disable the autodetection of columns from the table.

Executing this function clears the currently loaded column descriptors.

Parameters

auto_detect (bool) – True if the columns should be autodetected, False otherwise

Returns

self

clear_columns() None

Clear the current configuration of which columns should be loaded and how.

Returns

None

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the columns to be loaded from their columnDescriptors.

Executing this function disables autodetection of columns.

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

self

connections(connections: int) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the number of connections to read/write data from/to the database provider

Parameters

connections – number of connections

Returns

self

data_source_id(data_source_id: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the datasource ID.

Parameters

data_source_id – the datasource ID

Returns

self

jdbc_url(jdbc_url)

Set the jdbc URL to use for connecting to the DB.

Parameters

jdbc_url – the jdbc URL

Returns

self

keystore_alias(keystore_alias)

Set the keystore alias.

Parameters

keystore_alias – the keystore alias.

Returns

self

load() pypgx.api.frames._pgx_frame.PgxFrame

Load a PgxFrame from the database.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

load_async()

Load a PgxFrame from the database.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

name(frame_name: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the frame name.

Parameters

frame_name (str) – New name for the PgxFrame

Returns

self

owner(owner: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the owner of the table.

Parameters

owner – the owner

Returns

self

password(password: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the password of the database.

Parameters

password – the password

Returns

self

schema(schema: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the schema of the table.

Parameters

schema – the schema.

Returns

self

table_name(table_name: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the table name in the database.

Parameters

table_name – nodes table name.

Returns

self

username(username: str) pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Set the username of the database.

Parameters

username – username

Returns

self

class pypgx.api.frames.PgxDbFrameStorer(java_pgx_db_frame_storer)

Bases: object

Class for configuring the storing operation of a PgxFrame to a database and then triggering it.

clear_columns() None

Clear columns

Returns

self

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set columns

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

self

connections(connections: int) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the number of connections to read/write data from/to the database provider

Parameters

connections – number of connections

Returns

this storer

data_source_id(data_source_id: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the datasource ID.

Parameters

data_source_id – the datasource ID

Returns

this storer

jdbc_url(jdbc_url: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set jdbc url

Parameters

jdbc_url

Returns

keystore_alias(keystore_alias: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the keystore alias.

Parameters

keystore_alias – the keystore alias.

Returns

this storer

name(frame_name: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the frame name.

Parameters

frame_name – frame name.

Returns

self

overwrite(overwrite_bool: bool) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set overwrite

Parameters

overwrite_bool

Returns

self

owner(owner: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the owner of the table.

Parameters

owner – the owner

Returns

this storer

password(password: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the password of the database.

Parameters

password – the password

Returns

this storer

schema(schema: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the schema of the table.

Parameters

schema – the schema.

Returns

this storer

store() None

Store the PgxFrame.

Returns

None

store_async() None

Store the PgxFrame.

Returns

None

table_name(table_name: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the table name in the database.

Parameters

table_name – nodes table name.

Returns

self

username(username: str) pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Set the username of the database.

Parameters

username – username

Returns

this storer

class pypgx.api.frames.PgxFrame(java_pgx_frame)

Bases: pypgx.api._pgx_context_manager.PgxContextManager

Data-structure to load/store and manipulate tabular data.

It contains rows and columns. A PgxFrame can contain multiple columns where each column consist of elements of the same data type, and has a name. The list of the columns with their names and data types defines the schema of the frame. (The number of rows in the PgxFrame is not part of the schema of the frame.)

clone() pypgx.api.frames._pgx_frame.PgxFrame

Create a new PgxFrame with the same content as the current frame

Returns

PgxFrame

close() None

Free resources on the server taken up by this frame.

property columns: List[str]

Get the names of the columns contained in the PgxFrame.

Return type

list

count() int

Count number of elements in the frame.

destroy() None

Free resources on the server taken up by this frame.

flatten(*columns: str, inplace: bool = False)

Create a new PgxFrame with all the specified columns and vector columns flattened into multiple columns.

Parameters
  • columns – Column names

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

flatten_all(inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Create a new PgxFrame with all nested columns and vector columns flattened into multiple columns.

Parameters

inplace – Apply the changes inplace and return self

Returns

PgxFrame

get_column(name: str) pypgx.api.frames._pgx_frame.PgxFrameColumn

Return a PgxFrameColumn.

Parameters

name – Column name

Returns

PgxFrameColumn

get_column_descriptors() List[Tuple[str, str]]

Return a list containing the description of the different columns of the frames.

head(num_rows: int = 10, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Return the first num_rows elements of the frame

Parameters
  • num_rows – Number of rows to take

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

join(right: pypgx.api.frames._pgx_frame.PgxFrame, join_key_column: Optional[str] = None, left_join_key_column: Optional[str] = None, right_join_key_column: Optional[str] = None, left_prefix: Optional[str] = None, right_prefix: Optional[str] = None, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Create a new PgxFrame by performing a join operation.

Create a new PgxFrame by adding the columns of the right frame to this frame, aligned on equality of entries in column left_join_key_column for this frame and column right_join_key_column for the right frame, or join_key_columns on both frames. The resulting frame will contain the columns of this frame prefixed by left_prefix and the columns of right frame prefixed by right_prefix (if the prefixes are not null). Prefixes must ether not be set or both be set.

Parameters
  • right – PgxFrame whose columns will be added to the columns of this PgxFrame

  • join_key_column – Column of both frames on which the equality test will be performed

  • left_join_key_column – Column of this frame on which the equality test will be performed with right_join_key_column

  • right_join_key_column – Column of right frame on which the equality test will be performed with leftJoinKeyColumn

  • left_prefix – Prefix of the columns name of this frame in the resulting frame

  • right_prefix – Prefix of the columns name of right frame in the resulting frame

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

property length: int

Return the number of rows in the frame.

Returns

number of rows

print(file: Optional[TextIO] = None, num_results: int = 1000, start: int = 0) None

Print the frame.

Parameters
  • file – File to which results are printed (default is sys.stdout)

  • num_results – Number of results to be printed

  • start – Index of the first result to be printed

rename_column(old_column_name: str, new_column_name: str, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Return a PgxFrame with the column name modified.

Parameters
  • old_column_name – name of the column to rename

  • new_column_name – name of the column after the operation

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

rename_columns(column_renaming: Mapping[str, str], inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Return a PgxFrame with the column name modified.

Parameters
  • column_renaming – dict-like holding old_column names as keys and new column names as values

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

select(*columns: str, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Select multiple columns by column name.

Parameters
  • columns – Column names

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

store(path: str, file_format: str = 'csv', overwrite: bool = True) None

Store the frame in a file.

Parameters
  • path – Path where to store the frame

  • file_format – Storage format

  • overwrite – Overwrite current file

tail(num_rows: int = 10, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Return the last num_rows elements of the frame

Parameters
  • num_rows – Number of rows to take

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

to_pandas()

Convert to pandas DataFrame.

This method may change result_set cursor.

This method requires pandas.

Returns

PgxFrame as a Pandas Dataframe

to_pgql_result_set() pypgx.api._pgql_result_set.PgqlResultSet

Create a new PgqlResultSet having the same content as this frame.

Returns

PgqlResultSet

union(*frames: pypgx.api.frames._pgx_frame.PgxFrame, inplace: bool = False) pypgx.api.frames._pgx_frame.PgxFrame

Create a PgxFrame by concatenating the rows of this frame with the rows of the frames in frames. The different frames should have the same columns (same names, types and dimensions), in the same order. The resulting frame is not guaranteed to have any specific ordering of its rows.

Parameters
  • frames – Frames tu add through union

  • inplace – Apply the changes inplace and return self

Returns

PgxFrame

write() pypgx.api.frames._pgx_frame_storer.PgxGenericFrameStorer

Get Pgx Frame storer

Returns

PgxGenericFrameStorer

class pypgx.api.frames.PgxFrameBuilder(java_pgx_frame_builder)

Bases: object

A frame builder for constructing a PgxFrame.

add_rows(column_data: Dict[str, Any]) pypgx.api.frames._pgx_frame_builder.PgxFrameBuilder

Add the data to the frame builder.

Parameters

column_data – the column data in a dictionary

Returns

self

build(frame_name: str) pypgx.api.frames._pgx_frame.PgxFrame

Build the frame with the given frame name.

Parameters

frame_name – the name of the frame to create

Returns

the newly frame created

class pypgx.api.frames.PgxFrameColumn(java_pgx_frame_column)

Bases: pypgx.api._pgx_context_manager.PgxContextManager

Class representing one column of a PgxFrame.

destroy() None

Free resources on the server taken up by this column.

get_descriptor() Tuple[str, str]

Return a description of the column.

class pypgx.api.frames.PgxGenericFrameReader(java_pgx_generic_frame_reader)

Bases: object

A generic class for reading PgxFrame objects from various sources.

The class allows configuration of how the data should be read and facilitates the creation of specialized frame readers (PgxCsvFrameReader and PgxPgbFrameReader).

auto_detect_columns(auto_detect: bool) pypgx.api.frames._pgx_frame_reader.PgxGenericFrameReader

Enable or disable the autodetection of columns from the table.

Not all formats support autodetection of the columns (only DB in fact).

Executing this function clears the currently loaded column descriptors.

Parameters

auto_detect (bool) – True if the columns should be autodetected, False otherwise

Returns

self

clear_columns() None

Clear the current configuration of which columns should be loaded and how.

Returns

None

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_reader.PgxGenericFrameReader

Set the columns to be loaded from their columnDescriptors.

Executing this function disables autodetection of columns.

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

self

csv(uris: Optional[str] = None) pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader

Create a PgxCsvFrameReader object for loading CSV files from URIs.

Parameters

uris – List of paths to the csv files

Return type

PgxCsvFrameReader

csv_async(uris: str)

Read a PgxFrame from a list of URIs to CSV files.

Parameters

uris – list denoting the URIs

Returns

the read frame

db() pypgx.api.frames._pgx_frame_reader.PgxDbFrameReader

Create a PgxDbFrameReader object to load PgxFrame from a database.

Return type

PgxDbFrameReader

format(format: str) Union[pypgx.api.frames._pgx_frame_reader.PgxCsvFrameReader, pypgx.api.frames._pgx_frame_reader.PgxPgbFrameReader]

Return a frame reader for the type format specified.

Parameters

format (str) – format to be loaded

Returns

a loader for the format

Return type

PgxCsvFrameReader or PgxPgbFrameReader

name(frame_name: str) pypgx.api.frames._pgx_frame_reader.PgxGenericFrameReader

Set the frame name.

Parameters

frame_name (str) – New name for the PgxFrame

Returns

self

pgb(uris: Optional[str] = None) pypgx.api.frames._pgx_frame_reader.PgxPgbFrameReader

Create a PgxPgbFrameReader object for loading PGB files.

Parameters

uris – List of paths to the PGB files

Return type

PgxPgbFrameReader

pgb_async(uris: str)

Read a PgxFrame from a list of URIs to PGB files.

Parameters

uris – list denoting the URIs

Returns

the read frame

class pypgx.api.frames.PgxGenericFrameStorer(java_pgx_generic_frame_storer)

Bases: object

Class for configuring the storing operation of a PgxFrame and then triggering it.

csv() pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer

Get a PgxCsvFrameStorer instance for the PgxFrame

Return type

PgxCsvFrameStorer

db() pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer

Get a PgxDbFrameStorer instance for the PgxFrame

Return type

PgxDbFrameStorer

format(format: str) Union[pypgx.api.frames._pgx_frame_storer.PgxCsvFrameStorer, pypgx.api.frames._pgx_frame_storer.PgxPgbFrameStorer, pypgx.api.frames._pgx_frame_storer.PgxDbFrameStorer]

Create a specialized frame storer for saving the PgxFrame in a given format.

Parameters

format (str) – identifier of the wanted format. Can be one of ‘csv’, ‘pgb’ or ‘db’ (case insensitive)

Return type

PgxCsvFrameStorer, PgxPgbFrameStorer or PgxDbFrameStorer

name(frame_name: str) pypgx.api.frames._pgx_frame_storer.PgxGenericFrameStorer

Set the name of the stored frame.

Parameters

frame_name (str) – the new frame name

Returns

self

overwrite(overwrite_bool: bool) pypgx.api.frames._pgx_frame_storer.PgxGenericFrameStorer

Set overwrite

Parameters

overwrite_bool – denotes if the table should be overwritten.

Returns

self

pgb() pypgx.api.frames._pgx_frame_storer.PgxPgbFrameStorer

Get a PgxPgbFrameStorer instance for the PgxFrame.

Return type

PgxPgbFrameStorer

class pypgx.api.frames.PgxPgbFrameReader(java_pgx_pgb_frame_reader)

Bases: object

Class for reading PgxFrame objects from PGB files.

auto_detect_columns(auto_detect: bool) pypgx.api.frames._pgx_frame_reader.PgxPgbFrameReader

Enable or disable the autodetection of columns from the table.

Executing this function clears the currently loaded column descriptors.

Parameters

auto_detect (bool) – True if the columns should be autodetected, False otherwise

Returns

self

clear_columns() None

Clear the current configuration of which columns should be loaded and how.

Returns

None

columns(column_descriptors: List[Tuple[str, str]]) pypgx.api.frames._pgx_frame_reader.PgxPgbFrameReader

Set the columns to be loaded from their columnDescriptors.

Executing this function disables autodetection of columns.

Parameters

column_descriptors – List of tuples (columnName, columnType)

Returns

self

load(uris: str) pypgx.api.frames._pgx_frame.PgxFrame

Load a PgxFrame from the provided URIs.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

load_async(uris: str)

Load a PgxFrame from the provided URIs.

Parameters

uris – the URIs from which to load the frame

Returns

PgxFrame instance

name(frame_name: str) pypgx.api.frames._pgx_frame_reader.PgxPgbFrameReader

Set the frame name.

Parameters

frame_name (str) – New name for the PgxFrame

Returns

self

class pypgx.api.frames.PgxPgbFrameStorer(java_pgx_pgb_frame_storer)

Bases: object

Class for configuring the storing operation of a PgxFrame to a PGB file and then triggering it.

name(frame_name: str) pypgx.api.frames._pgx_frame_storer.PgxPgbFrameStorer

Set the frame name.

Parameters

frame_name – frame name.

Returns

this storer

overwrite(overwrite_bool: bool) pypgx.api.frames._pgx_frame_storer.PgxPgbFrameStorer

Set overwrite

Parameters

overwrite_bool – denotes if the table should be overwritten.

Returns

store() None

Store PgxFrame

Returns

PgxFrame instance

store_async()

Store PgxFrame

Returns

PgxFrame instance