phit

Reading CSV files

phit includes a native CSV reader, Phit\read_csv(), that tokenizes a file, guesses each column's type, and parses the values in Rust. Its rules follow readr 2 and match phibble's PHP reader. When the extension is loaded, phibble's DataFrame::fromCsv() uses it.

Edit the text below and the page reads it again. The sample shows several of the rules. A ZIP code with a leading zero stays text, quoted numbers with grouping marks read as doubles, and true and false spellings read as booleans. The invalid date 2026-02-30 fails to parse, and the short last row is padded with NA and reported as a problem.

Code

use function Phit\read_csv;

$result = read_csv($path, ['delimiter' => ',']);

$result['names'];     // column names
$result['columns'];   // per column: type, values, and the count that failed to parse
$result['problems'];  // ragged rows and unterminated quotes

$df = DataFrame::fromCsv($path);  // phibble, through the same reader

The phit documentation lists every option and guessing rule. In phibble's 1,000,000-row benchmark on an Apple Silicon Mac, DataFrame::fromCsv() takes 0.12 seconds with the extension and 1.0 seconds with the PHP reader.

Columns

Name Guessed type Missing Failed to parse
id int 0 0
zip string 0 0
signup date 1 1
last_seen datetime 1 0
plan string 0 0
active bool 1 0
monthly_spend float 2 0
visits int 2 0

Missing counts include the values that failed to parse, which the reader sets to NA.

Problems

  • row 7: expected 8 columns, got 5

Values

id zip signup last_seen plan active monthly_spend visits
1 02139 2026-01-15 2026-10-01 08:30:00 UTC basic TRUE 1250.5 12
2 10001 2026-02-03 2026-10-02 14:05:00 UTC pro FALSE 980 NA
3 94110 NA 2026-10-03 07:00:00 UTC basic TRUE 2001.75 7
4 60601 2026-03-12 NA team FALSE 410.25 3
5 73301 2026-04-01 2026-10-04 23:59:59 UTC pro TRUE NA 15
6 30301 2026-05-20 2026-10-05 12:00:00 UTC basic NA NA NA

The first 10 rows. Dates arrive as days since 1970-01-01 and datetimes as microseconds since the epoch in UTC; this table formats them.

Agreement with phibble's PHP reader

  • Column types: identical
  • Values: identical
  • Warnings: identical

One or more parsing issues: row 7: expected 8 columns, got 5; column 'signup': 1 value could not be parsed as date.