Type

class type.DataType

Represents a type of values in a DataFrame.

It is mapped to a type in database, including

  • A predefined type, such as integer for int and text for str in Python. In this case, name is specified for its name in database.

  • A user-defined composite type, for Python class. In this case, a type annotation object is provided such as the defined class.

A DataType object is callable. when called, it casts the object in the argument to the mapped type in database.

class type.TypeCast

An expression of type casting.

Example

>>> rows = [("01-01-1990",), ("05-01-98",)]
>>> df = db.create_dataframe(rows=rows, column_names=["date_str"])
>>> date_type = gp.type_("date")
>>> result = df.assign(date=lambda t: date_type(t["date_str"]))
>>> result
-------------------------
 date_str   | date
------------+------------
 01-01-1990 | 1990-01-01
 05-01-98   | 1998-05-01
-------------------------
(2 rows)
type.type_(name, schema=None, modifier=None)

Get access to a type predefined in database.

Parameters
  • name (str) – str: name of type

  • schema (Optional[str]) – Optional[str]: name of schema

  • modifier (Optional[int]) – Optional[int]: variable or fixed length depending on type

Returns

The predefined type as a Type object.

Return type

DataType