classPolarsField(Model,arbitrary_types_allowed=True):"""Polars Field model"""name:strdtype:Any# dtype: pl.PolarsDataType# Convertersdefto_dp(self)->models.IField:"""Convert to Table Schema Field Returns: Table Schema Field """# TypeField=models.Fieldifself.dtypeinARRAY_TYPES:Field=models.ArrayFieldelifself.dtypeinBOOLEAN_TYPES:Field=models.BooleanFieldelifself.dtypeinDATE_TYPES:Field=models.DateFieldelifself.dtypeinDATETIME_TYPES:Field=models.DatetimeFieldelifself.dtypeinDURATION_TYPES:Field=models.DurationFieldelifself.dtypeinINTEGER_TYPES:Field=models.IntegerFieldelifself.dtypeinNUMBER_TYPES:Field=models.NumberFieldelifself.dtypeinOBJECT_TYPES:Field=models.ObjectFieldelifself.dtypeinSTRING_TYPES:Field=models.StringFieldelifself.dtypeinTIME_TYPES:Field=models.TimeField# Namefield=Field(name=self.name)returnfield@classmethoddeffrom_dp(cls,field:models.IField)->PolarsField:"""Create Polars Field from Table Schema Field Parameters: field: Table Schema Field Returns: Polars Field """ifnotfield.name:raiseError(f"Field name is required to convert to polars: {field}")# Typedtype=pl.Utf8iffield.type=="array":dtype=pl.Listeliffield.type=="boolean":dtype=pl.Booleaneliffield.type=="date":dtype=pl.Dateeliffield.type=="datetime":dtype=pl.Datetimeeliffield.type=="duration":dtype=pl.Durationeliffield.type=="geojson":dtype=pl.Structeliffield.type=="geopoint":dtype=pl.Listeliffield.type=="integer":dtype=pl.Int64eliffield.type=="number":dtype=pl.Decimaleliffield.type=="object":dtype=pl.Structeliffield.type=="string":dtype=pl.Utf8eliffield.type=="time":dtype=pl.Timeeliffield.type=="year":dtype=pl.Int8eliffield.type=="yearmonth":dtype=pl.ListreturnPolarsField(name=field.name,dtype=dtype)
@classmethoddeffrom_dp(cls,field:models.IField)->PolarsField:"""Create Polars Field from Table Schema Field Parameters: field: Table Schema Field Returns: Polars Field """ifnotfield.name:raiseError(f"Field name is required to convert to polars: {field}")# Typedtype=pl.Utf8iffield.type=="array":dtype=pl.Listeliffield.type=="boolean":dtype=pl.Booleaneliffield.type=="date":dtype=pl.Dateeliffield.type=="datetime":dtype=pl.Datetimeeliffield.type=="duration":dtype=pl.Durationeliffield.type=="geojson":dtype=pl.Structeliffield.type=="geopoint":dtype=pl.Listeliffield.type=="integer":dtype=pl.Int64eliffield.type=="number":dtype=pl.Decimaleliffield.type=="object":dtype=pl.Structeliffield.type=="string":dtype=pl.Utf8eliffield.type=="time":dtype=pl.Timeeliffield.type=="year":dtype=pl.Int8eliffield.type=="yearmonth":dtype=pl.ListreturnPolarsField(name=field.name,dtype=dtype)
defto_dp(self)->models.IField:"""Convert to Table Schema Field Returns: Table Schema Field """# TypeField=models.Fieldifself.dtypeinARRAY_TYPES:Field=models.ArrayFieldelifself.dtypeinBOOLEAN_TYPES:Field=models.BooleanFieldelifself.dtypeinDATE_TYPES:Field=models.DateFieldelifself.dtypeinDATETIME_TYPES:Field=models.DatetimeFieldelifself.dtypeinDURATION_TYPES:Field=models.DurationFieldelifself.dtypeinINTEGER_TYPES:Field=models.IntegerFieldelifself.dtypeinNUMBER_TYPES:Field=models.NumberFieldelifself.dtypeinOBJECT_TYPES:Field=models.ObjectFieldelifself.dtypeinSTRING_TYPES:Field=models.StringFieldelifself.dtypeinTIME_TYPES:Field=models.TimeField# Namefield=Field(name=self.name)returnfield