Skip to content

DataType ​

Namespace: Polars.CSharp

Represents a Polars data type. Wraps the underlying Rust DataType Handle and provides high-level metadata.

Properties & Indexers ​

PropertyTypeDescription
ArrayShapeuint[]The shape of the array
ArrayWidthulongIf this is an Array type, returns the fixed width. Returns 0 if not an Array type.
BinaryDataType-
BooleanDataType-
CategoriesCategoriesReturn underlying Categories for categorical type, for other types returns null
DateDataType-
EnumCategoriesFrozenCategoriesReturn underlying FrozenCategories for enum type, for other types returns null
Float16DataType-
Float32DataType-
Float64DataType-
InnerTypeDataTypeReturn the inner type of list/array. Non-List/Array input will return null.
Int128DataType-
Int16DataType-
Int32DataType-
Int64DataType-
Int8DataType-
IsCategoricalbool-
IsDecimalbool-
IsEnumbool-
IsExtensionbool-
IsFloatbool-
IsIntegerbool-
IsNestedbool-
IsNumericboolReturns true if the type is a numeric type.
IsSignedIntegerbool-
IsTemporalbool-
IsUnsignedIntegerbool-
KindDataTypeKindGets the high-level kind of this data type.
NullDataType-
PrecisionintGets the decimal precision.
SameAsInputDataType-
ScaleintGets the decimal scale.
StringDataType-
StructFieldsIReadOnlyList<Field>Gets the fields of a Struct type. Returns null if this DataType is not a Struct.
TimeDataType-
TimeUnitTimeUnitGets the time unit for Datetime and Duration types.
TimeZonestringGets the timezone string for Datetime type. Returns null if the datetime has no timezone (naive datetime).
TimeZoneInfoTimeZoneInfoGets the timezone info for Datetime type. Returns null if the datetime has no timezone (naive datetime).
UInt128DataType-
UInt16DataType-
UInt32DataType-
UInt64DataType-
UInt8DataType-
UnknownDataType-

Constructors & Static Methods ​

Array ​

Create a Fixed-Size List (Array) data type.

Example: DataType.Array(DataType.Int32, 3),DataType.Array(typeof(int), 3)

csharp
public static DataType Array(DataType inner, params uint[] shape)

Parameters

NameTypeDescription
innerDataTypeThe data type of the elements.
shapeuint[]The shape of the arrays.

Categorical ​

Create a Categorical type

csharp
public static DataType Categorical(Categories? categories = null)
public static DataType Categorical(string categories)

Parameters

NameTypeDescription
categoriesCategories? / string-

Datetime ​

Create a datetime type with unit and timezone

csharp
public static DataType Datetime(TimeUnit unit = TimeUnit.Microseconds, string? timeZone = null)

Parameters

NameTypeDescription
unitTimeUnitprecision (ns, us, ms)
timeZonestring?timezone string (e.g. "Asia/Shanghai"), null for no timezone (Naive)

Decimal ​

Create a Decimal type

csharp
public static DataType Decimal(int precision = 38, int scale = 9)

Parameters

NameTypeDescription
precisionint-
scaleint-

Duration ​

Creates a Duration type. Default is Microseconds. Usage: DataType.Duration(TimeUnit.Nanoseconds)

csharp
public static DataType Duration(TimeUnit unit = TimeUnit.Microseconds)

Parameters

NameTypeDescription
unitTimeUnit-

Enum ​

Create a Enum type

csharp
public static DataType Enum(FrozenCategories categories)
public static DataType Enum(Series categories)
public static DataType Enum(string[] categories)
public static DataType Enum(Categories categories)
public static DataType Enum<T>()

Parameters

NameTypeDescription
categoriesFrozenCategories / Series / string[]-

Extension ​

Create an Extension data type

csharp
public static DataType Extension(string name, DataType inner, string? metadata = null)

Parameters

NameTypeDescription
namestringThe registered name of the extension type (e.g. "geoarrow.wkb")
innerDataTypeThe physical storage data type
metadatastring?Optional metadata string

FromArrowType ​

Generate DataType from ArrowType

csharp
public static DataType FromArrowType(IArrowType arrowType)

Parameters

NameTypeDescription
arrowTypeIArrowType-

FromNetType ​

Create a DataType from a .NET Type

csharp
public static DataType FromNetType<T>()

List ​

Creates a List type. Usage: DataType.List(DataType.Int32)

csharp
public static DataType List(DataType innerType)

Parameters

NameTypeDescription
innerTypeDataType-

Struct ​

Create Struct composite type.

csharp
public static DataType Struct(IEnumerable<Field> fields)
public static DataType Struct(params Field[] fields)
public static DataType Struct(IReadOnlyDictionary<string, DataType> fields)
public static DataType Struct(string[] names, DataType[] types)

Parameters

NameTypeDescription
fieldsIEnumerable<Field> / Field[] / IReadOnlyDictionary<string, DataType>Definition of a single field within a Struct DataType.
namesstring[]-
typesDataType[]-

Operators ​

operator == (Equality) ​

csharp
public static bool operator ==(DataType? left, DataType? right)

Parameters

NameTypeDescription
leftDataType?-
rightDataType?-

implicit operator ​

Implicitly convert System.Type to Polars DataType. Example: DataType dt = typeof(int); // dt is now DataType.Int32

csharp
public static implicit operator DataType(Type type)

Parameters

NameTypeDescription
typeType-

operator != (Inequality) ​

csharp
public static bool operator !=(DataType? left, DataType? right)

Parameters

NameTypeDescription
leftDataType?-
rightDataType?-

Instance Methods ​

GetArrowType ​

Get Apache Arrow Type

csharp
public IArrowType GetArrowType()

GetNetType ​

Get the .NET type corresponding to this DataType

csharp
public Type GetNetType()

ToDataTypeExpr ​

Convert this DataType to a DataTypeExpr literal. Equivalent to Python's polars.DataType.to_dtype_expr()

csharp
public DataTypeExpr ToDataTypeExpr()

Released under the MIT License. Powered by the Polars Rust core & Apache Arrow.