ihb2032/MoonFrame/types does not have a README file

    DataError

    pub(all) suberror DataError {
    ColumnNotFound(String)
    DuplicateColumn(String)
    TypeMismatch(String)
    LengthMismatch
    IndexOutOfBounds(Int)
    ParseError(String)
    InvalidOperation(String)
    IoError(String)
    Unsupported(String)
    NullInNonNullable(String)
    } derive(Eq,
    Debug
    )

    Unified error type for all MoonFrame operations.
    impl Show for DataError

    DataError::message

    fn DataError::message(self : DataError) -> String

    Human-readable message describing the error.

    DataType

    pub(all) enum DataType {
    Int
    Float
    Bool
    String
    Null
    } derive(Eq,
    Debug
    )

    Logical data type for a column.

    Null represents a column that carries no inferred type (e.g. an all-null CSV column where inference could not promote it to anything more specific). Concrete columns always carry one of the other variants.
    impl Show for DataType

    DataType::is_bool

    fn DataType::is_bool(self : DataType) -> Bool

    true only for the Bool variant.

    DataType::is_float

    fn DataType::is_float(self : DataType) -> Bool

    true only for the Float variant.

    DataType::is_integer

    fn DataType::is_integer(self : DataType) -> Bool

    true only for the Int variant.

    DataType::is_numeric

    fn DataType::is_numeric(self : DataType) -> Bool

    true for Int and Float — both are usable in numeric reductions.

    DataType::is_string

    fn DataType::is_string(self : DataType) -> Bool

    true only for the String variant.

    Field

    pub(all) struct Field {
    name : String
    dtype : DataType
    nullable : Bool
    } derive(Eq,
    Debug
    )

    Column metadata: a name, the column's logical DataType, and a declared nullable flag.

    nullable = false is a declared constraint that DataFrame::from_rows enforces: row data placing a Scalar::Null in such a column raises NullInNonNullable(name). (DataFrame::empty builds 0-row columns, so it can never violate the constraint.) The flag is otherwise advisory — it is neither inferred from a column's contents nor propagated across operations: Field::new (and so DataFrame::new, the IO readers, and the ops that rebuild through them) always sets nullable = true, so a nullable = false field only ever originates from an explicit Field::with_nullable(..., false) in a caller-supplied schema.
    impl Show for Field

    Field::dtype

    fn Field::dtype(self : Field) -> DataType

    The column's logical DataType.

    Field::name

    fn Field::name(self : Field) -> String

    The column's name.

    Field::new

    fn Field::new(name : String, dtype : DataType) -> Field

    Build a field with nullable = true (the common default for inferred CSV / JSON columns).

    Field::nullable

    fn Field::nullable(self : Field) -> Bool

    The declared nullable flag (see the type doc for how DataFrame::from_rows enforces it).

    Field::rename

    fn Field::rename(self : Field, new_name : String) -> Field

    Return a copy of this field with a new name.

    Field::with_nullable

    fn Field::with_nullable(name : String, dtype : DataType, nullable : Bool) -> Field

    Build a field with an explicit nullability flag.

    Scalar

    pub(all) enum Scalar {
    Int(Int64)
    Float(Double)
    Bool(Bool)
    String(String)
    Null
    } derive(Eq,
    Debug
    )

    A single cell value in a DataFrame.

    Null represents a missing value. All as_* conversions and comparisons involving Null raise TypeMismatch(...) — callers must check is_null() first or handle the error.

    The Float variant carries a 64-bit Double; the Int variant carries a 64-bit Int64. Use as_float for explicit access; Int is also accepted via numeric promotion to Double.
    impl Show for Scalar

    Scalar::as_bool

    fn Scalar::as_bool(self : Scalar) -> Bool raise DataError

    Bool cells return their value; other concrete variants and Null raise TypeMismatch(...).

    Scalar::as_float

    fn Scalar::as_float(self : Scalar) -> Double raise DataError

    Float cells return their Double; Int cells are promoted to Double; other concrete variants and Null raise TypeMismatch(...).

    Scalar::as_int

    fn Scalar::as_int(self : Scalar) -> Int64 raise DataError

    Int cells return their Int64; other concrete variants and Null raise TypeMismatch(...).

    Scalar::as_string

    fn Scalar::as_string(self : Scalar) -> String raise DataError

    String cells return their value; other concrete variants and Null raise TypeMismatch(...).

    Scalar::dtype

    fn Scalar::dtype(self : Scalar) -> DataType

    The DataType corresponding to this value's variant.

    Scalar::eq

    fn Scalar::eq(self : Scalar, other : Scalar) -> Bool raise DataError

    Equality between two Scalars. Two Nulls, or Null and a value, raise TypeMismatch — callers must guard nullability explicitly. Mixed numeric types (Int vs Float) compare after promoting Int to Double (the Float64 supertype, as in Polars); NaN follows IEEE 754 semantics (NaN == NaN is false).

    Precision caveat: the Int→Double promotion is lossy for an Int magnitude beyond 2^53, where a Double can no longer represent every integer, so two distinct large values can compare equal — e.g. Int(9223372036854775807) (2^63-1) promotes to 2^63, which equals Float(9.223372036854776e18). Same-dtype Int/Int comparisons are always exact; only the mixed Int-vs-Float arms widen.

    Scalar::gt

    fn Scalar::gt(self : Scalar, other : Scalar) -> Bool raise DataError

    Strict greater-than, defined as other.lt(self) — same Null-raise and ordering rules as lt. The delegation transposes the operands, so the incomparable-dtypes diagnostic is issued here first, in the caller's operand order — Int(1).gt(String("x")) reports "Int and String", not the transposed pair eq / lt / lte would never produce.

    Scalar::gte

    fn Scalar::gte(self : Scalar, other : Scalar) -> Bool raise DataError

    Greater-than-or-equal, defined as other.lte(self) — same rules as lte, with gt's call-order diagnostic for an incomparable pair.

    Scalar::is_null

    fn Scalar::is_null(self : Scalar) -> Bool

    true only for the Null (missing-value) variant.

    Scalar::lt

    fn Scalar::lt(self : Scalar, other : Scalar) -> Bool raise DataError

    Strict less-than. NaN follows IEEE 754: any comparison involving NaN returns false. Null short-circuits to raise. Mixed Int-vs-Float ordering widens Int to Double and shares eq's 2^53 precision caveat, so it can mis-order two distinct values across that boundary.

    Scalar::lte

    fn Scalar::lte(self : Scalar, other : Scalar) -> Bool raise DataError

    Less-than-or-equal — eq or lt. Shares their Null-raise and Int/Float promotion semantics.

    Scalar::to_string

    fn Scalar::to_string(self : Scalar) -> String

    Value-style rendering: Int(42) → "42", String("ab") → "ab", Null → "". Use the Show impl for the variant-form rendering.

    Schema

    pub(all) struct Schema {
    fields : Array[Field]
    } derive(Eq,
    Debug
    )

    Ordered list of Fields describing a DataFrame's columns.

    Construction always validates uniqueness of names; once built, a Schema is guaranteed to have no duplicate column names.
    impl Show for Schema

    Schema::field

    fn Schema::field(self : Schema, name : String) -> Field raise DataError

    Return the Field for name, or raise ColumnNotFound(name).

    Schema::field_at

    fn Schema::field_at(self : Schema, i : Int) -> Field raise DataError

    Return the Field at position i, or raise IndexOutOfBounds(i).

    Schema::field_names

    fn Schema::field_names(self : Schema) -> Array[String]

    Column names in declaration order.

    Schema::fields

    fn Schema::fields(self : Schema) -> Array[Field]

    Return a snapshot of the schema's fields.

    A fresh array is returned so callers cannot mutate the schema in place and break the "no duplicate names" invariant enforced by Schema::new.

    Schema::index_of

    fn Schema::index_of(self : Schema, name : String) -> Int raise DataError

    The index of the column named name, or raise ColumnNotFound(name).

    Schema::is_empty

    fn Schema::is_empty(self : Schema) -> Bool

    true when the schema has no columns.

    Schema::len

    fn Schema::len(self : Schema) -> Int

    Number of columns in the schema.

    Schema::new

    fn Schema::new(fields : Array[Field]) -> Schema raise DataError

    Build a schema from a list of fields. raise DuplicateColumn(name) on the first repeated name.

    The input array is copied, so mutating fields after construction cannot alter the schema or break the validated no-duplicates invariant.

    Schema::rename

    fn Schema::rename(self : Schema, old_name : String, new_name : String) -> Schema raise DataError

    Rename old_name to new_name. Raises if old_name is missing or new_name collides with another existing column.

    Schema::select

    fn Schema::select(self : Schema, names : Array[String]) -> Schema raise DataError

    Project a sub-schema by name, preserving the order of names. Missing names raise ColumnNotFound(name); duplicates inside names raise DuplicateColumn(name).

    compare_string_lex

    fn compare_string_lex(a : String, b : String) -> Int

    Lexicographic string comparison by UTF-16 code unit, returning the usual -1 / 0 / 1. MoonBit's built-in < / Compare on String is shortlex (length first, then code unit) — e.g. "fig" < "apple" is true because "fig" is shorter, which surprises users expecting dictionary order. Every user-facing ordering in MoonFrame (Scalar::lt, Series::min / max, DataFrame::sort) routes through this helper instead of the built-in operator so they all agree.

    Ordering is by UTF-16 code unit, so it matches pandas / SQL dictionary order across the Basic Multilingual Plane (the common case). It can diverge for supplementary-plane characters, whose surrogate code units (0xD800–0xDBFF) sort below high-BMP code points rather than above them — a code-point-accurate comparison is deferred to a later release.

    double_fits_int64

    fn double_fits_int64(n : Double) -> Bool

    Whether n falls in the range Double::to_int64 converts faithfully — i.e. within Int64's representable range. Int64::MIN = -2^63 is exactly representable as a Double; Int64::MAX = 2^63 - 1 is not — the largest Double strictly below 2^63 is 9223372036854774784 (2^63 - 1024), and anything above it rounds to a Double >= 2^63 that would overflow Int64. NaN is out of range (every comparison with it is false). The shared guard that Float->Int casting (@column) and JSON integer reading (@io) both check before calling Double::to_int64, whose result is implementation-defined outside this range. Total.

    escape_debug

    fn escape_debug(s : String) -> String

    Escape s for embedding inside a double-quoted debug rendering: a backslash becomes \\, a double quote becomes \", and the control characters newline / carriage-return / tab become \n / \r / \t. Every other control character — the rest of the C0 range, DEL, and the Unicode line/paragraph separators NEL / LS / PS — becomes a \uXXXX escape, so a hostile payload (e.g. an ESC from a malformed CSV header) cannot inject a newline or forge an extra line into the quoted form. (The escape set targets line injection; the C1 range 0x80–0x9F is left as-is — harmless under UTF-8 output, which emits it as multi-byte sequences rather than raw 8-bit controls.) A single forward pass, so a backslash introduced here is never itself re-escaped. Total — pure string assembly, no failure path.

    fold_extremum

    fn[T] fold_extremum(n : Int, get : (Int) -> T, skip : (Int) -> Bool, better : (T, T) -> Bool) -> T?

    Fold the cells 0 ..< n to their extremum, skipping every cell that skip(i) marks (a null slot, plus NaN for a Float column) and using better(candidate, best) to decide whether a kept cell replaces the running best. Returns None when every cell is skipped — an empty range, an all-null column, or an all-NaN Float column. The single extremum accumulation behind min / max (whole-column, per-group, and per-scope), so each caller supplies only its reader, skip test, and comparator. Generic over the cell type T, so the element kind lives entirely in the caller's closures. Total — pure folding, no failure path.

    is_decimal_int_literal

    fn is_decimal_int_literal(s : String) -> Bool

    true when s is an optional + / - sign followed by one or more ASCII decimal digits and nothing else. Empty / sign-only strings, 0x / 0o / 0b base prefixes, and 1_000 underscore grouping all return false.

    Numeric recognition lives here, in types, so every layer agrees on what counts as an integer literal: the CSV / JSON readers' type inference and the @column String→Int cast all route through this one predicate before handing the text to @string.parse_int64. That parser defaults to base = 0 and would otherwise silently accept hex / octal / binary prefixes (0xFF → 255) and underscores (1_000 → 1000) — forms pandas / polars keep as strings. Sharing the screen (the way every ordering routes through compare_string_lex) keeps an explicit cast consistent with what the reader inferred for the same text.

    parse_decimal_int_opt

    fn parse_decimal_int_opt(s : String) -> Int64?

    Parse a plain base-10 integer, or None. Screens out 0x / 0o / 0b prefixes and 1_000 underscore grouping via is_decimal_int_literal (the forms pandas / polars keep as strings), then hands the text to @string.parse_int64, mapping its failure (a value beyond Int64's range, say) to None. The shared routine behind the CSV reader's Int inference and the @column String→Int cast, so an inferred column and an explicit cast agree on what text is an integer.

    parse_plain_double_opt

    fn parse_plain_double_opt(s : String) -> Double?

    Parse a "plain" Double, or None. Rejects 1_000-style underscore grouping up front (@string.parse_double would accept it, but pandas / polars keep such cells as strings), then hands the text to @string.parse_double. The nan / inf / infinity literals it recognises are returned as-is — the caller decides whether to keep them (the CSV reader gates them behind allow_nonfinite; the @column String→Float cast accepts them). A finite literal beyond the Double range collapses to a signed Infinity (IEEE 754 overflow), exactly like the explicit inf literal — so it too is gated by allow_nonfinite on the CSV path, rather than being rejected as unparseable. Shared so inference and an explicit cast agree on what text is a Float.