fromJson static method
- Map<
String, Object?> json
Decodes a descriptor from its protocol JSON form.
Throws a FormatException when the kind is not recognized.
Implementation
static DType fromJson(Map<String, Object?> json) {
final kind = json['kind'];
final simple = _simple[kind];
if (simple != null) return simple;
return switch (kind) {
'decimal' => DecimalType(
precision: json['precision'] as int,
scale: json['scale'] as int,
),
'datetime' => DateTimeType(
TimeUnit.fromJson(json['unit'] as String),
timeZone: json['timeZone'] as String?,
),
'duration' => DurationType(TimeUnit.fromJson(json['unit'] as String)),
'array' => ArrayType(
fromJson((json['inner'] as Map).cast()),
json['width'] as int,
),
'list' => ListType(fromJson((json['inner'] as Map).cast())),
'object' => ObjectType(json['label'] as String),
'unknown' => UnknownType.fromJson(json),
'categorical' => CategoricalType(
name: json['name'] as String,
namespace: json['namespace'] as String,
hash: _parseUnsigned64(json['hash'], 'hash'),
physical: CategoricalPhysical.fromJson(json['physical'] as String),
),
'enum' => EnumType((json['categories'] as List).cast<String>()),
'struct' => StructType(
(json['fields'] as List).map((field) {
final map = (field as Map).cast<String, Object?>();
return Field(
map['name'] as String,
fromJson((map['dtype'] as Map).cast<String, Object?>()),
);
}),
),
'extension' => ExtensionType(
json['name'] as String,
fromJson((json['storage'] as Map).cast<String, Object?>()),
metadata: json['metadata'] as String?,
),
_ => throw FormatException('Unknown Polars datatype kind: $kind'),
};
}