When folders named 01 and 1 become the same test group
Two folders are labeled 01 and 1. They hold different sets of test questions. To a person reading the names, they’re easy to tell apart. To software reading them as numbers, both are simply one. Ask for group 01, and how many folders should it open?
In our fictional test, we converted the request for 01 to the type the reader had chosen. It brought back four cases, three correct. The intended group held only two, both correct. We ran the request again after adding a folder called control. The original files hadn’t changed, yet this time just the two intended cases came back.
Our test data lived in Parquet files, which store tables in columns. Each group had a folder such as fold=01. The part after the equals sign was the group’s ID. The software scanned the folder names to work out what kind of values it was reading. The crucial choice was whether to treat those IDs as text or whole numbers.
We started with fold=01, fold=1 and fold=02. Group 01 contained case-a and case-b, both correct. The PyArrow 26.0.1 file reader saw digits in all three names and inferred a whole-number field. We converted the requested 01 to the type it inferred. As a number, 01 became 1. Asking for that value brought back both the 01 and 1 folders, with three correct answers among their four cases.
Next we added a file under fold=control. That added a nonnumeric label to this test. When PyArrow scanned the folders again it inferred text for the group IDs, and the text 01 matched just one folder. This time only case-a and case-b counted. The new control case itself stayed outside the test. Every original path and file byte was unchanged.
The table calls each original file a shard. An ‘explicit string schema’ means telling the reader to treat the folder labels as text. DuckDB calls its text type VARCHAR.
| Reader and partition setting | Three original shards | With the control shard |
|---|---|---|
| PyArrow inferred | Integer, 3/4 correct | String, 2/2 correct |
| PyArrow with explicit string schema | String, 2/2 correct | String, 2/2 correct |
| DuckDB inferred or explicit text | VARCHAR, 2/2 correct | VARCHAR, 2/2 correct |
The second row shows what happened when we told PyArrow to treat the folder IDs as text from the start. Both requests returned the intended two cases. In this example DuckDB 1.4.4 kept 01 and 1 separate too, whether it inferred text or we specified it.
If a leading zero identifies a different group, set the folder IDs to text before the reader scans them. Save both the type the reader used and the exact case IDs it selected. They let someone check what a score of two out of two actually covers.
The reader settings are described in the PyArrow partition schema and DuckDB partition types documentation.