graviti.portex.base#

The base elements of Portex type.

Module Contents#

Classes#

PortexType

The base class of portex type.

PortexRecordBase

The base class of record like Portex types.

Functions#

read_yaml(path)

Read a yaml file into Portex type.

read_json(path)

Read a json file into Portex type.

Attributes#

graviti.portex.base.PYARROW_TYPE_ID_TO_PORTEX_TYPE[source]#
class graviti.portex.base.PortexType[source]#

The base class of portex type.

property imports(self)[source]#

Get the PortexType imports.

Returns

The Imports instance of this PortexType.

Return type

graviti.portex.package.Imports

classmethod from_pyobj(cls, content, _imports=None)[source]#

Create Portex type instance from python dict.

Parameters
Returns

A Portex type instance created from the input python dict.

Return type

_T

classmethod from_pyarrow(cls, paarray)[source]#

Create Portex type instance from PyArrow type.

Parameters
  • paarray (pyarrow.Array) – The PyArrow array.

  • cls (Type[_T]) –

Raises

TypeError – When the PyArrow type is not supported.

Returns

The created Portex type instance.

Return type

_T

classmethod from_json(cls, content)[source]#

Create Portex type instance from JSON string.

Parameters
  • content (str) – A JSON string representing a Portex type.

  • cls (Type[_T]) –

Returns

A Portex type instance created from the input JSON string.

Return type

_T

classmethod from_yaml(cls, content)[source]#

Create Portex type instance from YAML string.

Parameters
  • content (str) – A YAML string representing a Portex type.

  • cls (Type[_T]) –

Returns

A Portex type instance created from the input YAML string.

Return type

_T

to_pyobj(self, _with_imports=True)[source]#

Dump the instance to a python dict.

Returns

A python dict representation of the Portex type.

Parameters

_with_imports (bool) –

Return type

Dict[str, Any]

to_json(self)[source]#

Dump the instance to a JSON string.

Returns

A JSON representation of the Portex type.

Return type

str

to_yaml(self)[source]#

Dump the instance to a YAML string.

Returns

A YAML representation of the Portex type.

Return type

str

abstract to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow DataType.

Raises

NotImplementedError – The method of the base class should not be called.

Returns

The corresponding builtin PyArrow DataType.

Parameters

_to_backend (bool) –

Return type

pyarrow.DataType

abstract to_builtin(self)[source]#

Expand the top level type to Portex builtin type.

Raises

NotImplementedError – The method of the base class should not be called.

Return type

graviti.portex.builtin.PortexBuiltinType

copy(self)[source]#

Get a copy of the portex type.

Returns

A copy of the portex type.

Parameters

self (_T) –

Return type

_T

class graviti.portex.base.PortexRecordBase[source]#

Bases: PortexType, graviti.utility.UserMutableMapping[str, PortexType]

The base class of record like Portex types.

insert(self, index, name, portex_type)[source]#

Insert the name and portex_type at the index.

Parameters
  • index (int) – The index to insert the field.

  • name (str) – The name of the field to be inserted.

  • portex_type (PortexType) – The portex_type of the field to be inserted.

Return type

None

astype(self, name, portex_type)[source]#

Convert the type of the field with the given name to the new PortexType.

Parameters
  • name (str) – The name of the field to convert.

  • portex_type (PortexType) – The new PortexType of the field to convert to.

Return type

None

rename(self, old_name, new_name)[source]#

Rename the name of a field.

Parameters
  • old_name (str) – The current name of the field to be renamed.

  • new_name (str) – The new name of the field to assign.

Return type

None

to_pyarrow(self, *, _to_backend=False)[source]#

Convert the Portex type to the corresponding builtin PyArrow StructType.

Returns

The corresponding builtin PyArrow StructType.

Parameters

_to_backend (bool) –

Return type

pyarrow.StructType

graviti.portex.base.read_yaml(path)[source]#

Read a yaml file into Portex type.

Parameters

path (graviti.utility.PathLike) – The path of the yaml file.

Returns

A Portex type instance created from the input yaml file.

Return type

PortexType

graviti.portex.base.read_json(path)[source]#

Read a json file into Portex type.

Parameters

path (graviti.utility.PathLike) – The path of the json file.

Returns

A Portex type instance created from the input json file.

Return type

PortexType