nodejs-polars
Version:
Polars: Blazingly fast DataFrames in Rust, Python, Node.js, R and SQL
254 lines (253 loc) • 8.48 kB
TypeScript
import { Field } from "./field";
export declare abstract class DataType {
readonly __dtype: string;
get variant(): DataTypeName;
protected identity: string;
protected get inner(): null | any[];
equals(other: DataType): boolean;
/** Null type */
static get Null(): Null;
/** `true` and `false`. */
static get Bool(): Bool;
/** An `i8` */
static get Int8(): Int8;
/** An `i16` */
static get Int16(): Int16;
/** An `i32` */
static get Int32(): Int32;
/** An `i64` */
static get Int64(): Int64;
/** An `u8` */
static get UInt8(): UInt8;
/** An `u16` */
static get UInt16(): UInt16;
/** An `u32` */
static get UInt32(): UInt32;
/** An `u64` */
static get UInt64(): UInt64;
/** A `f32` */
static get Float32(): Float32;
/** A `f64` */
static get Float64(): Float64;
static get Date(): Date;
/** Time of day type */
static get Time(): Time;
/** Type for wrapping arbitrary JS objects */
static get Object(): Object_;
/** A categorical encoding of a set of strings */
static get Categorical(): Categorical;
/** Decimal type */
static Decimal(precision?: number, scale?: number): Decimal;
/**
* Calendar date and time type
* @param timeUnit any of 'ms' | 'ns' | 'us'
* @param timeZone timezone string as defined by Intl.DateTimeFormat `America/New_York` for example.
*/
static Datetime(timeUnit?: TimeUnit | "ms" | "ns" | "us", timeZone?: string | null | undefined): Datetime;
/**
* Nested list/array type
*
* @param inner The `DataType` of values within the list
*
*/
static List(inner: DataType): List;
/**
* List of fixed length
* This is called `Array` in other polars implementations, but `Array` is widely used in JS, so we use `FixedSizeList` instead.
*
*/
static FixedSizeList(inner: DataType, listSize: number): FixedSizeList;
/**
* Struct type
*/
static Struct(fields: Field[]): DataType;
static Struct(fields: {
[key: string]: DataType;
}): DataType;
/** A variable-length UTF-8 encoded string whose offsets are represented as `i64`. */
static get Utf8(): Utf8;
static get String(): String;
toString(): string;
toJSON(): {
[x: string]: {
[x: string]: any;
};
} | {
[x: string]: DataTypeName;
};
asFixedSizeList(): (this & FixedSizeList) | null;
}
export declare class Null extends DataType {
__dtype: "Null";
}
export declare class Bool extends DataType {
__dtype: "Bool";
}
export declare class Int8 extends DataType {
__dtype: "Int8";
}
export declare class Int16 extends DataType {
__dtype: "Int16";
}
export declare class Int32 extends DataType {
__dtype: "Int32";
}
export declare class Int64 extends DataType {
__dtype: "Int64";
}
export declare class UInt8 extends DataType {
__dtype: "UInt8";
}
export declare class UInt16 extends DataType {
__dtype: "UInt16";
}
export declare class UInt32 extends DataType {
__dtype: "UInt32";
}
export declare class UInt64 extends DataType {
__dtype: "UInt64";
}
export declare class Float32 extends DataType {
__dtype: "Float32";
}
export declare class Float64 extends DataType {
__dtype: "Float64";
}
export declare class Date extends DataType {
__dtype: "Date";
}
export declare class Time extends DataType {
__dtype: "Time";
}
export declare class Object_ extends DataType {
__dtype: "Object";
}
export declare class Utf8 extends DataType {
__dtype: "Utf8";
}
export declare class String extends DataType {
__dtype: "String";
}
export declare class Categorical extends DataType {
__dtype: "Categorical";
}
export declare class Decimal extends DataType {
__dtype: "Decimal";
private precision;
private scale;
constructor(precision?: number, scale?: number);
get inner(): (number | null)[];
equals(other: DataType): boolean;
toJSON(): {
[x: string]: {
[x: string]: {
precision: number | null;
scale: number | null;
};
};
};
}
/**
* Datetime type
*/
export declare class Datetime extends DataType {
private timeUnit;
private timeZone?;
__dtype: "Datetime";
constructor(timeUnit?: TimeUnit | "ms" | "ns" | "us", timeZone?: string | null | undefined);
get inner(): (string | null | undefined)[];
equals(other: DataType): boolean;
}
export declare class List extends DataType {
protected __inner: DataType;
__dtype: "List";
constructor(__inner: DataType);
get inner(): DataType[];
equals(other: DataType): boolean;
}
export declare class FixedSizeList extends DataType {
protected __inner: DataType;
protected listSize: number;
__dtype: "FixedSizeList";
constructor(__inner: DataType, listSize: number);
get inner(): [DataType, number];
equals(other: DataType): boolean;
toJSON(): {
[x: string]: {
[x: string]: {
type: {
[x: string]: {
[x: string]: any;
};
} | {
[x: string]: DataTypeName;
};
size: number;
};
};
};
}
export declare class Struct extends DataType {
__dtype: "Struct";
private fields;
constructor(inner: {
[name: string]: DataType;
} | Field[]);
get inner(): Field[];
equals(other: DataType): boolean;
toJSON(): any;
}
/**
* Datetime time unit
*/
export declare enum TimeUnit {
Nanoseconds = "ns",
Microseconds = "us",
Milliseconds = "ms"
}
/**
* @ignore
* Timeunit namespace
*/
export declare namespace TimeUnit {
function from(s: "ms" | "ns" | "us"): TimeUnit;
}
/**
* Datatype namespace
*/
export declare namespace DataType {
type Categorical = import(".").Categorical;
type Int8 = import(".").Int8;
type Int16 = import(".").Int16;
type Int32 = import(".").Int32;
type Int64 = import(".").Int64;
type UInt8 = import(".").UInt8;
type UInt16 = import(".").UInt16;
type UInt32 = import(".").UInt32;
type UInt64 = import(".").UInt64;
type Float32 = import(".").Float32;
type Float64 = import(".").Float64;
type Bool = import(".").Bool;
type Utf8 = import(".").Utf8;
type String = import(".").String;
type List = import(".").List;
type FixedSizeList = import(".").FixedSizeList;
type Date = import(".").Date;
type Datetime = import(".").Datetime;
type Time = import(".").Time;
type Object = import(".").Object_;
type Null = import(".").Null;
type Struct = import(".").Struct;
type Decimal = import(".").Decimal;
/**
* deserializes a datatype from the serde output of rust polars `DataType`
* @param dtype dtype object
*/
function deserialize(dtype: any): DataType;
}
export type DataTypeName = "Null" | "Bool" | "Int8" | "Int16" | "Int32" | "Int64" | "UInt8" | "UInt16" | "UInt32" | "UInt64" | "Float32" | "Float64" | "Decimal" | "Date" | "Datetime" | "Utf8" | "Categorical" | "List" | "Struct";
export type JsType = number | boolean | string;
export type JsToDtype<T> = T extends number ? DataType.Float64 : T extends boolean ? DataType.Bool : T extends string ? DataType.Utf8 : never;
export type DTypeToJs<T> = T extends DataType.Decimal ? bigint : T extends DataType.Float64 ? number : T extends DataType.Int64 ? bigint : T extends DataType.Int32 ? number : T extends DataType.Bool ? boolean : T extends DataType.Utf8 ? string : never;
export type DTypeToJsLoose<T> = T extends DataType.Decimal ? number | bigint : T extends DataType.Float64 ? number | bigint : T extends DataType.Int64 ? number | bigint : T extends DataType.Int32 ? number | bigint : T extends DataType.Bool ? boolean : T extends DataType.Utf8 ? string : never;
export type DtypeToJsName<T> = T extends DataType.Decimal ? "Decimal" : T extends DataType.Float64 ? "Float64" : T extends DataType.Float32 ? "Float32" : T extends DataType.Int64 ? "Int64" : T extends DataType.Int32 ? "Int32" : T extends DataType.Int16 ? "Int16" : T extends DataType.Int8 ? "Int8" : T extends DataType.UInt64 ? "UInt64" : T extends DataType.UInt32 ? "UInt32" : T extends DataType.UInt16 ? "UInt16" : T extends DataType.UInt8 ? "UInt8" : T extends DataType.Bool ? "Bool" : T extends DataType.Utf8 ? "Utf8" : never;