Write a data dictionary from table exports.
Done by an agent. Checked twice.
Every column of every table described with its type, a real example, its counts and the oddities a newcomer would hit.
Real files in
- aggregation_level_titles.csv
BLS aggregation level code titles, trimmed to the 9 county levels. Values unchanged.. 10 lines, 450 bytes. - county_employment_2023.csv
BLS Quarterly Census of Employment and Wages, 2023 annual averages for Pitkin County, Colorado. Trimmed to the 54 rows at county, ownership, supersector and sector level and to 16 of the 38 columns. Values unchanged.. 55 lines, 4 KB. - industry_titles.csv
BLS industry code titles, trimmed to the 36 codes used in the county table. Values unchanged.. 37 lines, 1 KB. - ownership_titles.csv
BLS ownership code titles, all 8 rows. 9 lines, 210 bytes.
Real public documents. Links below.
Three steps
- 1.Read every table
- 2.Describe every column
- 3.Write the dictionary
Claude Sonnet 5.5, 1 min 3 s. No web. It never saw the check.
Checked twice
- Passed: 22 of 22 columns across 4 tables have one row each in dictionary.csv
- Passed: 22 of 22 column types equal the type the written rules give
- Passed: 22 of 22 examples are real values found in that column of the file
- Passed: 22 of 22 blank counts and distinct counts equal the counts rebuilt from the files
- Passed: 14 of 14 number columns have the right smallest and largest value
- Passed: 22 of 22 columns carry exactly the oddity codes the rules give (9 columns have at least one)
- Passed: 4 of 4 tables have a section in notes.md that opens with the right row count
- Passed: 22 of 22 rows of dictionary.csv sit in file name order with columns in the order of the file
- Passed: 90 of 90 numbers written in notes.md are a number in a cell of the files or a count rebuilt from them and 58 of 58 values set in code marks are copied exactly from the files
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 6 ways on purpose. The check caught 5.
table,column,type,example,blank_count,distinct_count,min,max,oddities aggregation_level_titles.csv,agglvl_code,whole number,70,0,9,70,78, aggregation_level_titles.csv,agglvl_title,text,"County, Total Covered",0,9,,, county_employment_2023.csv,area_fips,text,08097,0,1,,,one_value;leading_zeros county_employment_2023.csv,own_code,whole number,0,0,5,0,5, county_employment_2023.csv,industry_code,text,10,0,36,,,mixed_numbers_and_text county_employment_2023.csv,agglvl_code,whole number,70,0,5,70,74, county_employment_2023.csv,size_code,whole number,0,0,1,0,0,one_value county_employment_2023.csv,year,whole number,2023,0,1,2023,2023,one_value county_employment_2023.csv,qtr,text,A,0,1,,,one_value county_employment_2023.csv,disclosure_code,text,N,50,1,,,has_blanks;one_value county_employment_2023.csv,annual_avg_estabs,whole number,2180,0,33,1,2180,
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are real public documents.
Run 2 of 2 on 1 December 2026. The agent took 1 min 3 s. Run 1 did not pass the check. Each run starts clean. Between runs the written flow was made clearer, or a check was corrected or made stricter. Nobody edits the output.
What the second review verified
- I recomputed all 22 dictionary rows (type, blank_count, distinct_count, min, max, oddities) from input/. Every one matches, for example annual_avg_wkly_wage is a whole number with 37 distinct values from 0 to 6536, and oty_annual_avg_emplvl_pct_chg is a decimal from -16.4 to 29.1 flagged has_negatives.
- The row counts in notes.md match the files: 9, 54, 36 and 8. area_fips is 08097 in every row, so it is correctly typed as text with one_value;leading_zeros.
- The 4 disclosure_code N rows are own_code 5 with industries 11, 21, 22 and 42. They have estabs of 16, 3, 3 and 34, all other measures are 0, and the pct change is written '0' while other zero rows use '0.0'. No row has an employment of 0 without the N.
- The links hold: every own_code, industry_code and agglvl_code in the employment table appears in its title table. Ownership codes 4, 8 and 9 and levels 75 to 78 are unused. own_code 1 has industry 102 (level 72) and industry 10 (level 71), both with 69 employment and 5970814 wages. There are 54 distinct own_code and industry_code pairs.
What this run does not show
- The check was fixed after the first run because it read a row count from the wrong place in the notes. The second run passed the corrected check.
- The notes are free writing. The check shows each number in them exists in the files but misses a right number in the wrong sentence, as one planted error still shows.
- The tables are a cut of one county's public employment file, 16 of its 38 columns. What each column means is not tested, only its type, counts and oddities.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 5 of 6. The check was made stricter after the first try at this, and the same untouched output was graded again. It let these through, so on this job they rest on the second review alone:
- Changed the number 74 to 76 in notes.md
Open every file
flow.md · the three steps the agent followed
# Write a data dictionary from table exports function: data for: the analyst who has to hand a set of tables to someone new goal: Every column in every table is described with its type, a real example, its counts and the oddities a new user would trip on. ## 1. Read every table Read every csv file in input/. Each file is one table and its first row holds the column names. Read every value as text exactly as it is written. Do not let a tool turn 007 into 7 or drop a blank. A value is blank when nothing is left after removing spaces. ## 2. Describe every column For each column of each table work out: - type, using the first of these that fits: `empty` when every value is blank. `whole number` when every value that is not blank is digits with an optional minus sign in front and none of them has a leading zero. A leading zero is a first character 0 in a value longer than one character. `decimal` when every value that is not blank is a number and at least one has a decimal point. `text` for anything else. A column of digits with a leading zero is text. - example: one real value from the column, not blank, copied exactly. - blank_count: how many values are blank. - distinct_count: how many different values there are, not counting blanks. Compare values as text: 0 and 0.0 are two different values. - min and max: the smallest and largest value, for `whole number` and `decimal` columns only. - oddities, any of these codes that apply: `has_blanks` some values are blank and some are not. `one_value` every value that is not blank is the same. `leading_zeros` every value that is not blank is digits only and at least one has a leading zero. `mixed_numbers_and_text` some values that are not blank are numbers and some are not. `has_negatives` a `whole number` or `decimal` column with a value below zero. ## 3. Write the dictionary Write output/dictionary.csv with columns table,column,type,example,blank_count,distinct_count,min,max,oddities. One row per column, tables in file name order and columns in the order they appear. table is the file name. oddities holds the codes joined with a semicolon, or nothing. Write output/notes.md for the new user. One section per table with its file name as the heading, a first line `Rows: N` (not counting the header row), one sentence on what a row stands for and a short list of things to watch for when using the table. Base every warning on values you can point to in the files. Say which columns link one table to another. If a meaning is not in the files, say it is not known. Do not guess. ## Done looks like - Every column of every table has one row in dictionary.csv. - Every type, count, example and oddity can be rebuilt from the files. - notes.md gives the row count of every table and warns only about things that are in the data.
input/aggregation_level_titles.csv · 10 lines, 450 bytes
agglvl_code,agglvl_title 70,"County, Total Covered" 71,"County, Total -- by ownership sector" 72,"County, by Domain -- by ownership sector" 73,"County, by Supersector -- by ownership sector" 74,"County, NAICS Sector -- by ownership sector" 75,"County, NAICS 3-digit -- by ownership sector" 76,"County, NAICS 4-digit -- by ownership sector" 77,"County, NAICS 5-digit -- by ownership sector" 78,"County, NAICS 6-digit -- by ownership sector"
input/county_employment_2023.csv · 55 lines, 4 KB
area_fips,own_code,industry_code,agglvl_code,size_code,year,qtr,disclosure_code,annual_avg_estabs,annual_avg_emplvl,total_annual_wages,annual_avg_wkly_wage,avg_annual_pay,lq_annual_avg_emplvl,oty_annual_avg_emplvl_chg,oty_annual_avg_emplvl_pct_chg 08097,0,10,70,0,2023,A,,2180,17691,1351492124,1469,76394,1.00,749,4.4 08097,1,10,71,0,2023,A,,9,69,5970814,1668,86743,0.20,-10,-12.7 08097,1,102,72,0,2023,A,,9,69,5970814,1668,86743,0.21,-10,-12.7 08097,1,1021,73,0,2023,A,,5,26,2025518,1513,78661,0.34,-4,-13.3 08097,1,1028,73,0,2023,A,,4,43,3945296,1761,91574,0.23,-5,-10.4 08097,1,48-49,74,0,2023,A,,5,26,2025518,1513,78661,0.36,-4,-13.3 08097,1,92,74,0,2023,A,,4,43,3945296,1761,91574,0.23,-5,-10.4 08097,2,10,71,0,2023,A,,1,8,668457,1659,86253,0.01,0,0.0 08097,2,102,72,0,2023,A,,1,8,668457,1659,86253,0.02,0,0.0 08097,2,1028,73,0,2023,A,,1,8,668457,1659,86253,0.04,0,0.0 08097,2,92,74,0,2023,A,,1,8,668457,1659,86253,0.04,0,0.0 08097,3,10,71,0,2023,A,,14,2405,192988678,1543,80256,1.46,114,5.0 08097,3,102,72,0,2023,A,,14,2405,192988678,1543,80256,1.47,114,5.0 08097,3,1021,73,0,2023,A,,3,49,4208580,1666,86626,0.76,-1,-2.0 08097,3,1025,73,0,2023,A,,4,883,71991694,1567,81500,0.87,16,1.8 08097,3,1028,73,0,2023,A,,7,1473,116788404,1525,79300,3.06,98,7.1 08097,3,22,74,0,2023,A,,3,49,4208580,1666,86626,1.69,-1,-2.0 08097,3,61,74,0,2023,A,,3,404,26210247,1247,64823,0.45,3,0.7 08097,3,62,74,0,2023,A,,1,479,45781447,1838,95577,4.43,13,2.8 08097,3,92,74,0,2023,A,,7,1473,116788404,1525,79300,3.06,98,7.1 08097,5,10,71,0,2023,A,,2156,15210,1151864175,1456,75732,1.00,646,4.4 08097,5,101,72,0,2023,A,,190,965,105390054,2101,109231,0.37,76,8.5 08097,5,1011,73,0,2023,A,,19,112,7604770,1308,68001,0.53,-22,-16.4 08097,5,1012,73,0,2023,A,,156,742,91618310,2373,123406,0.81,91,14.0 08097,5,1013,73,0,2023,A,,15,111,6166974,1072,55768,0.07,8,7.8 08097,5,102,72,0,2023,A,,1967,14245,1046474121,1413,73463,1.14,570,4.2 08097,5,1021,73,0,2023,A,,299,1984,119852051,1162,60419,0.60,173,9.6 08097,5,1022,73,0,2023,A,,44,126,12486086,1906,99096,0.37,0,0.0 08097,5,1023,73,0,2023,A,,432,1525,160445903,2023,105193,1.52,-15,-1.0 08097,5,1024,73,0,2023,A,,543,2015,218319606,2084,108361,0.77,-15,-0.7 08097,5,1025,73,0,2023,A,,126,652,50205946,1480,76954,0.23,-1,-0.2 08097,5,1026,73,0,2023,A,,237,7110,429863440,1163,60458,3.74,382,5.7 08097,5,1027,73,0,2023,A,,277,826,54693163,1274,66248,1.57,47,6.0 08097,5,1029,73,0,2023,A,,11,7,607926,1631,84827,0.22,-1,-12.5 08097,5,11,74,0,2023,A,N,16,0,0,0,0,0,0,0 08097,5,21,74,0,2023,A,N,3,0,0,0,0,0,0,0 08097,5,22,74,0,2023,A,N,3,0,0,0,0,0,0,0 08097,5,23,74,0,2023,A,,156,742,91618310,2373,123406,0.81,91,14.0 08097,5,31-33,74,0,2023,A,,15,111,6166974,1072,55768,0.07,8,7.8 08097,5,42,74,0,2023,A,N,34,0,0,0,0,0,0,0 08097,5,44-45,74,0,2023,A,,237,1469,92851248,1216,63221,0.82,80,5.8 08097,5,48-49,74,0,2023,A,,26,386,13712929,683,35533,0.52,87,29.1 08097,5,51,74,0,2023,A,,44,126,12486086,1906,99096,0.37,0,0.0 08097,5,52,74,0,2023,A,,106,256,53334461,4004,208202,0.35,4,1.6 08097,5,53,74,0,2023,A,,326,1269,107111442,1623,84401,4.60,-19,-1.5 08097,5,54,74,0,2023,A,,357,925,125808196,2617,136082,0.75,20,2.2 08097,5,55,74,0,2023,A,,60,103,34949549,6536,339866,0.35,-17,-14.2 08097,5,56,74,0,2023,A,,126,987,57561861,1121,58295,0.91,-19,-1.9 08097,5,61,74,0,2023,A,,25,261,20574445,1518,78930,0.72,16,6.5 08097,5,62,74,0,2023,A,,101,392,29631501,1455,75639,0.16,-16,-3.9 08097,5,71,74,0,2023,A,,67,2659,179897335,1301,67648,9.26,212,8.7 08097,5,72,74,0,2023,A,,170,4451,249966105,1080,56163,2.76,170,4.0 08097,5,81,74,0,2023,A,,277,826,54693163,1274,66248,1.57,47,6.0 08097,5,99,74,0,2023,A,,11,7,607926,1631,84827,0.22,-1,-12.5
input/industry_titles.csv · 37 lines, 1 KB
industry_code,industry_title 10,"10 Total, all industries" 101,101 Goods-producing 1011,1011 Natural resources and mining 1012,1012 Construction 1013,1013 Manufacturing 102,102 Service-providing 1021,"1021 Trade, transportation, and utilities" 1022,1022 Information 1023,1023 Financial activities 1024,1024 Professional and business services 1025,1025 Education and health services 1026,1026 Leisure and hospitality 1027,1027 Other services 1028,1028 Public administration 1029,1029 Unclassified 11,"NAICS 11 Agriculture, forestry, fishing and hunting" 21,"NAICS 21 Mining, quarrying, and oil and gas extraction" 22,NAICS 22 Utilities 23,NAICS 23 Construction 31-33,NAICS 31-33 Manufacturing 42,NAICS 42 Wholesale trade 44-45,NAICS 44-45 Retail trade 48-49,NAICS 48-49 Transportation and warehousing 51,NAICS 51 Information 52,NAICS 52 Finance and insurance 53,NAICS 53 Real estate and rental and leasing 54,"NAICS 54 Professional, scientific, and technical services" 55,NAICS 55 Management of companies and enterprises 56,NAICS 56 Administrative and support and waste management and remediation services 61,NAICS 61 Educational services 62,NAICS 62 Health care and social assistance 71,"NAICS 71 Arts, entertainment, and recreation" 72,NAICS 72 Accommodation and food services 81,NAICS 81 Other services (except public administration) 92,NAICS 92 Public administration 99,NAICS 99 Unclassified
input/ownership_titles.csv · 9 lines, 210 bytes
own_code,own_title 0,Total Covered 1,Federal Government 2,State Government 3,Local Government 4,International Government 5,Private 8,Total Government 9,Total U.I. Covered (Excludes Federal Government)
output/dictionary.csv · written by the agent, 23 lines
table,column,type,example,blank_count,distinct_count,min,max,oddities aggregation_level_titles.csv,agglvl_code,whole number,70,0,9,70,78, aggregation_level_titles.csv,agglvl_title,text,"County, Total Covered",0,9,,, county_employment_2023.csv,area_fips,text,08097,0,1,,,one_value;leading_zeros county_employment_2023.csv,own_code,whole number,0,0,5,0,5, county_employment_2023.csv,industry_code,text,10,0,36,,,mixed_numbers_and_text county_employment_2023.csv,agglvl_code,whole number,70,0,5,70,74, county_employment_2023.csv,size_code,whole number,0,0,1,0,0,one_value county_employment_2023.csv,year,whole number,2023,0,1,2023,2023,one_value county_employment_2023.csv,qtr,text,A,0,1,,,one_value county_employment_2023.csv,disclosure_code,text,N,50,1,,,has_blanks;one_value county_employment_2023.csv,annual_avg_estabs,whole number,2180,0,33,1,2180, county_employment_2023.csv,annual_avg_emplvl,whole number,17691,0,37,0,17691, county_employment_2023.csv,total_annual_wages,whole number,1351492124,0,37,0,1351492124, county_employment_2023.csv,annual_avg_wkly_wage,whole number,1469,0,37,0,6536, county_employment_2023.csv,avg_annual_pay,whole number,76394,0,37,0,339866, county_employment_2023.csv,lq_annual_avg_emplvl,decimal,1.00,0,39,0,9.26, county_employment_2023.csv,oty_annual_avg_emplvl_chg,whole number,749,0,30,-22,749,has_negatives county_employment_2023.csv,oty_annual_avg_emplvl_pct_chg,decimal,4.4,0,35,-16.4,29.1,has_negatives industry_titles.csv,industry_code,text,10,0,36,,,mixed_numbers_and_text industry_titles.csv,industry_title,text,"10 Total, all industries",0,36,,, ownership_titles.csv,own_code,whole number,0,0,8,0,9, ownership_titles.csv,own_title,text,Total Covered,0,8,,,
output/notes.md · written by the agent, 61 lines
# Notes for the new user Four tables. Every statement below comes from the csv files in input/. Anything the files do not say is marked "not known". `dictionary.csv` has one row per column with type, example, counts, min/max and oddity codes. How the tables link (column names match exactly, values match in every row): - `county_employment_2023.csv` `own_code` -> `ownership_titles.csv` `own_code` - `county_employment_2023.csv` `industry_code` -> `industry_titles.csv` `industry_code` - `county_employment_2023.csv` `agglvl_code` -> `aggregation_level_titles.csv` `agglvl_code` Every code used in the employment table is found in its title table. There are no gaps. ## aggregation_level_titles.csv Rows: 9 One row stands for one aggregation level code (70 to 78) and its title. Watch for: - Only codes 70 to 74 appear in `county_employment_2023.csv`. Codes 75, 76, 77 and 78 (NAICS 3-digit to 6-digit) are in this table but have no rows in the employment table. - Titles contain commas and are quoted in the file (for example "County, Total Covered"). Use a real csv reader. ## county_employment_2023.csv Rows: 54 One row stands for one combination of area, ownership code and industry code, with its 2023 annual figures (establishments, employment level, wages, pay, location quotient and over-the-year change). Watch for: - `area_fips` is `08097` in every row, so there is one area. It has a leading zero, so read it as text. Reading it as a number gives 8097. What the code names (a county is implied by the file name) is not known from the files; there is no area title table. - `year` (2023), `qtr` (A) and `size_code` (0) each hold one value in every row. What `qtr` A and `size_code` 0 mean is not known. - `industry_code` mixes numbers and text. Values such as `31-33`, `44-45` and `48-49` are ranges, so do not read the column as a number. - `industry_code` `10` appears with two aggregation levels, 70 (own_code 0) and 71 (other own_codes). `industry_code` alone does not tell you the level. - `disclosure_code` is blank in 50 rows and `N` in 4 rows. Those 4 rows are own_code 5 with industry codes 11, 21, 22 and 42. In them every measure from `annual_avg_emplvl` to `oty_annual_avg_emplvl_pct_chg` is 0 while `annual_avg_estabs` is 3 to 34. No row with `annual_avg_emplvl` of 0 lacks the `N`. What `N` means is not known from the files, so do not treat those zeros as real zero employment without checking the source. - Zero is written two ways in `oty_annual_avg_emplvl_pct_chg`: `0` in the 4 `N` rows and `0.0` in other rows. They count as different values. - `oty_annual_avg_emplvl_chg` and `oty_annual_avg_emplvl_pct_chg` have negative values (lowest -22 and -16.4). - `lq_annual_avg_emplvl` is a decimal. Its values have two places (for example `1.00`) except the zeros in the `N` rows, which are written `0`. - Rows at different levels repeat the same figures. For example own_code 1 has `102` (level 72) and `10` (level 71), both with 69 employment and 5970814 wages. Adding all rows together would count the same employment more than once. Pick one `agglvl_code` before you add up. - `own_code` 0 has one row only (industry 10, level 70). The codes 1, 2, 3 and 5 have rows at levels 71 to 74. Ownership codes 4, 8 and 9 have no rows in this table. - Each own_code and industry_code pair occurs once (54 rows, 54 pairs). ## industry_titles.csv Rows: 36 One row stands for one industry code and its title. Watch for: - `industry_code` mixes numbers and text (`31-33`, `44-45`, `48-49`), so keep it as text. - The title already starts with the code (for example `1011 Natural resources and mining`, `NAICS 11 Agriculture, forestry, fishing and hunting`). - Some titles contain commas and are quoted in the file. - All 36 codes are used in `county_employment_2023.csv`. ## ownership_titles.csv Rows: 8 One row stands for one ownership code (0, 1, 2, 3, 4, 5, 8, 9) and its title. Watch for: - Codes 4, 8 and 9 (International Government, Total Government, Total U.I. Covered (Excludes Federal Government)) have no rows in `county_employment_2023.csv`. - Titles such as "Total Covered" and "Total Government" suggest totals, but how they relate to the other codes is not stated in the files.
check.py · the check, written before the run
"""Rebuilds the data dictionary from the table exports and compares it with what the agent wrote."""
import csv, re, sys
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def num(s):
try: return float(str(s).strip())
except ValueError: return None
whole = lambda v: re.fullmatch(r"-?\d+", v) is not None
number = lambda v: re.fullmatch(r"-?(\d+\.?\d*|\.\d+)", v) is not None
lead0 = lambda v: len(v) > 1 and v[0] == "0" and v.isdigit()
want, nrows, in_files, tallies, texts = {}, {}, set(), set(), {"dictionary.csv", "notes.md"}
for f in sorted((root/"input").glob("*.csv")):
rows = list(csv.reader(f.open())); head, body = rows[0], rows[1:]; nrows[f.name] = len(body)
tallies |= {len(body), len(head)}; texts |= {f.name} | set(head)
for i, col in enumerate(head):
vals = [r[i].strip() if i < len(r) else "" for r in body]; full = [v for v in vals if v]
texts |= set(full)
in_files |= {float(x) for v in full for x in re.findall(r"\d+(?:\.\d+)?", v)} # every number written in a cell
tallies |= {len(full), len(vals) - len(full), len(set(full))} | {full.count(v) for v in set(full)}
odd = set()
if not full: typ = "empty"
elif all(whole(v) for v in full) and not any(lead0(v) for v in full): typ = "whole number"
elif all(number(v) for v in full) and any("." in v for v in full) and not all(v.isdigit() for v in full): typ = "decimal"
else: typ = "text"
if full and len(full) < len(vals): odd.add("has_blanks")
if full and len(set(full)) == 1: odd.add("one_value")
if full and all(v.isdigit() for v in full) and any(lead0(v) for v in full): odd.add("leading_zeros")
if any(number(v) for v in full) and not all(number(v) for v in full): odd.add("mixed_numbers_and_text")
isnum = typ in ("whole number", "decimal")
if isnum and any(float(v) < 0 for v in full): odd.add("has_negatives")
want[(f.name, col)] = {"type": typ, "values": set(full), "blank": len(vals) - len(full), "distinct": len(set(full)),
"min": min(map(float, full)) if isnum else None, "max": max(map(float, full)) if isnum else None, "odd": odd}
path = root/"output/dictionary.csv"
if not path.exists():
say(False, "output/dictionary.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {((r.get("table") or "").strip(), (r.get("column") or "").strip()): r for r in rows}
n = len(want)
have = len(set(got) & set(want))
say(have == n and len(rows) == n, f"{have} of {n} columns across {len(nrows)} tables have one row each in dictionary.csv")
def count(test): return sum(1 for k, w in want.items() if k in got and test(got[k], w))
t = count(lambda g, w: (g.get("type") or "").strip().lower() == w["type"])
say(t == n, f"{t} of {n} column types equal the type the written rules give")
e = count(lambda g, w: (g.get("example") or "").strip() in w["values"] or (not w["values"] and not (g.get("example") or "").strip()))
say(e == n, f"{e} of {n} examples are real values found in that column of the file")
c = count(lambda g, w: num(g.get("blank_count")) == w["blank"] and num(g.get("distinct_count")) == w["distinct"])
say(c == n, f"{c} of {n} blank counts and distinct counts equal the counts rebuilt from the files")
nums = [k for k, w in want.items() if w["min"] is not None]
m = sum(1 for k in nums if k in got and num(got[k].get("min")) == want[k]["min"] and num(got[k].get("max")) == want[k]["max"])
others_blank = count(lambda g, w: w["min"] is not None or (not (g.get("min") or "").strip() and not (g.get("max") or "").strip()))
say(m == len(nums) and others_blank == n, f"{m} of {len(nums)} number columns have the right smallest and largest value")
o = count(lambda g, w: {x.strip().lower() for x in (g.get("oddities") or "").split(";") if x.strip()} == w["odd"])
flagged = sum(1 for w in want.values() if w["odd"])
say(o == n, f"{o} of {n} columns carry exactly the oddity codes the rules give ({flagged} columns have at least one)")
notes = (root/"output/notes.md").read_text() if (root/"output/notes.md").exists() else ""
def section(name): # the text under the heading that carries the file name, as the flow asks for
m = re.search(r"^#+[^\n]*" + re.escape(name) + r"[^\n]*$", notes, re.M)
return notes[m.end():] if m else ""
parts = {name: section(name) for name in nrows}
r = sum(1 for name, cnt in nrows.items() if (lambda mm: mm is not None and int(mm.group(1)) == cnt)(re.search(r"Rows:\D{0,6}(\d+)", parts[name])))
say(r == len(nrows), f"{r} of {len(nrows)} tables have a section in notes.md that opens with the right row count")
placed = [k for k in got if k in want] == list(want)
say(placed and have == n, f"{have if placed else 0} of {n} rows of dictionary.csv sit in file name order with columns in the order of the file")
# a number written in the notes has to be a number in a cell of the files or a count rebuilt from them
tallies |= {len(nrows), len(want)}
written = re.findall(r"(?<![\w.])\d[\d,]*(?:\.\d+)?(?![\w]*\.csv)", notes)
def known(tok):
x = float(tok.replace(",", "")); return x in in_files or ("." not in tok and int(x) in tallies)
kn = sum(1 for t in written if known(t))
# a value set in code marks has to be a cell value, a column name or a file name, copied exactly
texts |= {"empty", "whole number", "decimal", "text", "has_blanks", "one_value", "leading_zeros", "mixed_numbers_and_text", "has_negatives"}
marked = [q.strip() for q in re.findall(r"`([^`\n]+)`", notes)]
mk = sum(1 for q in marked if q in texts)
say(len(written) > 0 and kn == len(written) and mk == len(marked), f"{kn} of {len(written)} numbers written in notes.md are a number in a cell of the files or a count rebuilt from them and {mk} of {len(marked)} values set in code marks are copied exactly from the files")
sys.exit(0 if ok else 1)
aggregation_level_titles.csv: public document. Fingerprint 9421acc813f0.
county_employment_2023.csv: public document. Fingerprint 9d7b1f142a9d.
industry_titles.csv: public document. Fingerprint f00d7d43ae5f.
ownership_titles.csv: public document. Fingerprint 7b34dbbc607a.
dictionary.csv: written by the agent. Fingerprint 53f32c8f699e.
notes.md: written by the agent. Fingerprint f2fb0ad0aa5d.