You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
arrow-cast numeric parsers fail to parse whitespace-padded strings #9538
The Parser::parse implementations for numeric types fail to parse strings that contain leading or trailing whitespace.
In practice, this happens quite often when reading data from CSVs or other text-based sources where values may be padded with spaces, tabs, or newline characters. Instead of parsing successfully, these inputs currently return None.
To Reproduce
use arrow_array::types::*;use arrow_cast::parse::Parser;// they return None instead of the parsed numberassert_eq!(Float32Type::parse(" 1.5 "),None);// expected Some(1.5)assert_eq!(Int32Type::parse(" 42 "),None);// expected Some(42)assert_eq!(Int64Type::parse("\t100\n"),None);// expected Some(100)assert_eq!(UInt64Type::parse(" 7 "),None);// expected Some(7)
Expected behavior
Numeric parsers should ignore leading and trailing whitespace before parsing. For example, " 42 " should parse successfully to Some(42) rather than returning None.
This behavior is consistent with how most data ingestion systems handle text-to-number conversion.
Additional context
The issue originates in arrow-cast/src/parse.rs. The float parsers pass string.as_bytes() directly to lexical_core::parse, and the parser_primitive! macro (used for integers and durations) similarly operates on the input without trimming.
A simple fix would be to call .trim() on the input string before attempting to parse.
Numeric parsers should ignore leading and trailing whitespace before parsing. For example, " 42 " should parse successfully to Some(42) rather than returning None.
This behavior is consistent with how most data ingestion systems handle text-to-number conversion.
I did some brief checking of postgres and duckdb and they indeed do trim spaces
Interestingly DuckDB does automatically trim
andrewlamb@Andrews-MacBook-Pro-3:~/Software/influxdb_pro/ent$ duckdb
DuckDB v1.5.0 (Variegata)
Enter ".help" for usage hints.
memory D select' 4.5'::float;
┌────────────────────────┐
│ CAST(' 4.5'AS FLOAT) │
│ float │
├────────────────────────┤
│ 4.5 │
└────────────────────────┘
As does postgres 🤔
andrewlamb@Andrews-MacBook-Pro-3:~/Software/influxdb_pro/ent$ psql -h localhost -U postgres
psql (14.22 (Homebrew), server 11.16 (Debian 11.16-1.pgdg90+1))
Type "help" for help.
postgres=# select ' 4.5'::float;
float8
--------4.5
(1 row)
Activity
alamb commentedon Mar 19, 2026
Copying some comments from #9537
I guess question comes down to expectations
I did some brief checking of postgres and duckdb and they indeed do trim spaces
Interestingly DuckDB does automatically trim
As does postgres 🤔
Rich-T-kid commentedon Jul 16, 2026
take
support white space prefixed parse for ints and floats (#10374)
support suffix white space in arrow-cast parse (apache#10396)