graviti.portex.field#

Portex record field releated classes.

Module Contents#

Classes#

FrozenFields

Represents a frozen fields dict.

Fields

Represents a Portex record fields dict.

ConnectedFields

Fields composed of FrozenFields and Fields.

Attributes#

class graviti.portex.field.FrozenFields(items=None)[source]#

Bases: graviti.utility.FrozenNameOrderedDict[graviti.portex.base.PortexType]

Represents a frozen fields dict.

Parameters

items (Union[Iterable[Tuple[str, _V]], Mapping[str, _V], None]) –

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 (graviti.portex.base.PortexType) – The portex_type of the field to be inserted.

Raises

TypeError – When calling this method of FrozenFields.

Return type

None

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

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

Parameters
Raises

TypeError – When calling this method of FrozenFields.

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.

Raises

TypeError – When calling this method of FrozenFields.

Return type

None

class graviti.portex.field.Fields(fields=None)[source]#

Bases: graviti.utility.NameOrderedDict[graviti.portex.base.PortexType], FrozenFields

Represents a Portex record fields dict.

Parameters

fields (Union[Iterable[Tuple[str, graviti.portex.base.PortexType]], Mapping[str, graviti.portex.base.PortexType], None]) –

property imports(self)[source]#

Get the Fields imports.

Returns

The Imports instance of this Fields.

Return type

graviti.portex.package.Imports

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 (graviti.portex.base.PortexType) – The portex_type of the field to be inserted.

Raises

KeyError – When the name already exists in the Fields.

Return type

None

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

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

Parameters
Raises

KeyError – When the name does not exist in the Fields.

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

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

Create Portex fields dict instance from python list.

Parameters
  • content (List[Dict[str, Any]]) – A python list representing a Portex fields dict.

  • imports (Optional[graviti.portex.package.Imports]) – The imports of the Portex fields dict.

Returns

A Portex fields dict instance created from the input python list.

Return type

Fields

to_pyobj(self)[source]#

Dump the instance to a python list.

Returns

A Python List representation of the fields dict.

Return type

List[Dict[str, Any]]

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

Convert the fields to a list of PyArrow Field.

Returns

A list of PyArrow Field representing the fields of Portex record.

Parameters

_to_backend (bool) –

Return type

List[pyarrow.Field]

copy(self)[source]#

Get a copy of the fields.

Returns

A copy of the fields.

Parameters

self (_T) –

Return type

_T

graviti.portex.field.UnionFields[source]#
class graviti.portex.field.ConnectedFields(multi_fields)[source]#

Bases: MutableMapping[str, graviti.portex.base.PortexType]

Fields composed of FrozenFields and Fields.

Raises

ValueError – When there as repeated field names.

Parameters

multi_fields (Iterable[UnionFields]) – The FrozenFields and Fields.

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 (graviti.portex.base.PortexType) – The portex_type of the field to be inserted.

Raises
  • ValueError – When the name already exists in the fields.

  • TypeError – When trying to insert a field into FrozenFields.

Return type

None

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

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

Parameters
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