Choose a type from the meaning of the field. An amount encoded as text needs conversion for arithmetic. A numeric-looking account identifier often needs to keep its spelling. Keep the raw field while validating a new feed.

​
Convert text to a number

Add a parsed column and inspect it beside the source.

from chalk import _, functions as F
from chalkdf import DataFrame

tx = DataFrame({
    "account": ["001", "002", "003", "004", "005"],
    "raw": ["12", "0", "", "unknown", None],
})

parsed = tx.with_columns(_.raw.cast(int).alias("amount"))
parsed.run()
#
accountstring
rawstring
amountint64
10011212
200200
3003null
4004unknownnull
5005nullnull

For these string-to-integer conversions, the empty string and the malformed value produce null. The valid string “0” becomes zero. The original null remains null.

​
Find failed conversions

A null result alone cannot tell you whether the input was absent or malformed. Select rows where a value was supplied but parsing returned null.

parsed.filter(F.is_not_null(_.raw) & F.is_null(_.amount)).select("account", "raw").run()
#
accountstring
rawstring
1003
2004unknown

This gives you the two records to investigate while leaving genuinely missing source values out of the error count.

​
Choose precision before arithmetic

Casting these floating-point amounts to integers rounds them to the nearest integer. Compare representations before selecting a storage type for amounts.

values = DataFrame({"amount": [12.75, -3.5, 0.0]})
values.project({
    "original": _.amount,
    "integer": _.amount.cast(int),
    "rounded": F.round(_.amount, 0),
}).run()
#
originaldouble
integerint64
roundeddouble
112.751313.0
2-3.5-4-4.0
30.000.0

The result types differ: the cast produces integers and rounding retains floating-point values. If the downstream field represents cents, establish the scale and rounding convention before converting.

​
Preserve identifiers across a conversion

Cast the parsed amount back to text for a display field and keep the original account ID as its own column.

parsed.filter(F.is_not_null(_.amount)).project({
    "account": _.account,
    "display_amount": _.amount.cast(str),
}).run()
#
accountstring
display_amountlarge_string
100112
20020

An integer representation of the account would lose its leading zeros. Converting it back to a string would give a different join key.

​
Parse timestamps before comparing them

Two timestamps with different offsets can represent the same instant. Parse their ISO 8601 text so comparisons use time values.

events = DataFrame({"stamp": ["2025-01-01T12:00:00Z", "2025-01-01T07:00:00-05:00"]})
events.project({
    "source": _.stamp,
    "is_noon_utc": F.from_iso8601_timestamp(_.stamp) == F.from_iso8601_timestamp("2025-01-01T12:00:00Z"),
}).run()
#
sourcestring
is_noon_utcbool
12025-01-01T12:00:00ZTrue
22025-01-01T07:00:00-05:00True

Keep the source field if the offset as originally written matters. Both parsed rows represent noon UTC.

​
Check the range before narrowing an integer

Inspect values at the boundary when a downstream schema requires fewer bits. Use an explicit Arrow type for the destination.

import pyarrow as pa

counts = DataFrame({"raw": [0, 127, 128]})
counts.project({"raw": _.raw, "narrow": _.raw.cast(pa.int8())}).run()
#
rawint64
narrowint8
100
2127127
3128null

A signed eight-bit integer holds values from -128 through 127. Keep the original field while checking the conversion.

See missing data and DataFrame.project.