mostlyright.core.formats.csv
mostlyright.core.formats.csv
Section titled “mostlyright.core.formats.csv”CSV format — pandas-native serialization.
dumps emits standard CSV without the index column. loads parses
via pd.read_csv with pandas’ default dtype inference. Useful for
spreadsheet interchange and shell-level inspection, but lossy:
- All dtype information is lost on the wire; pandas re-infers on read.
Int64becomesint64orfloat64(depending on whether the column has nulls);Categoricalbecomesobject(strings);booleanbecomesobjectif it contained nulls. NaNandNoneand empty cells are all written as the empty string and all read back asNaN. The distinction between “missing numeric” and “missing string” is not preserved.- Timezone-aware timestamps serialize as their ISO-8601 representation
with offset, and
pd.read_csvparses them back as object strings unless the caller explicitly asks forparse_dates. - Floating-point round-trip is subject to CSV’s lossy decimal representation — pandas uses repr() formatting by default which is generally exact for IEEE-754, but precision-critical callers should prefer parquet.
For lossless transport prefer parquet. For LLM-friendly tabular transport prefer TOON.
Functions
Section titled “Functions”dumps(df) | Serialize a DataFrame to a CSV string. |
|---|---|
loads(data) | Parse a CSV string back into a DataFrame. |
mostlyright.core.formats.csv.dumps(df)
Section titled “mostlyright.core.formats.csv.dumps(df)”Serialize a DataFrame to a CSV string.
Drops the index (index=False) to match the wire shape the
catalog adapters emit. Column order is preserved.
Phase 6 W2-T6: accepts pandas OR polars input; polars frames are converted to pandas at the boundary so the wire bytes stay identical regardless of caller backend.
- Return type:
str - Parameters: df (DataFrame)
mostlyright.core.formats.csv.loads(data)
Section titled “mostlyright.core.formats.csv.loads(data)”Parse a CSV string back into a DataFrame.
Uses pandas’ default dtype inference — see module docstring for the loss cases callers must be aware of.
- Return type:
DataFrame - Parameters: data (str)