fio-l1-nyc-csvwkt-addresses

Status: done
Score: 1.000
Duration: 0:47
Cost: 0.21¢
Model: google/gemma-4-26b-a4b-it

Map (reference ← swipe → agent)

0:00
The vendor SQL export `nyc_addresses` needs proper GeoParquet so `WHERE recorded_at > '2024-01-01'` and `SUM(unit_count)` work without CASTs. Convert it to `addresses.geoparquet`: Point geometry in EPSG:4326, `recorded_at` as `timestamp[us]`, `unit_count` as `int32`, all other columns as string.
0:00
System info
{
  "adapter": "openrouter",
  "model": "google/gemma-4-26b-a4b-it",
  "base_url": "https://openrouter.ai/api/v1"
}
0:01
Bash ls -F
nyc_addresses.csv
0:03
Bash head -n 5 nyc_addresses.csv
"id","country","postcode","street","number","unit","postal_city","recorded_at","unit_count","geometry_wkt"
"0005eda0-2540-4e36-bc81-dfb52e323d99","US","10002","ALLEN ST","37","1/2","","2024-01-01T00:00:00Z","0","POINT (-73.9922338 40.716163)"
"00587e13-6253-485d-9258-e47d43af7559","US","10038","MADISON ST","45","","","2024-01-12T07:13:17Z","0","POINT (-73.9983308 40.71204)"
"0070f126-d36a-43b3-b767-a8fbb7156602","US","10038","PECK SLIP","44","","","2024-01-23T14:26:34Z","0","POINT (-74.0015005 40.7073293)"
"00a8fc38-5d9a-42da-94a9-7d2f4101f82c","US","11201","FRONT ST","11","","","2024-02-03T21:39:51Z","0","POINT (-73.9928578 40.702681)"
0:16
Write /work/solve.py
content · 61 lines · py
# /// script
# requires-python = ">=3.12"
# dependencies = ["geopandas", "shapely", "pyarrow", "pandas"]
# ///

import pandas as pd
import geopandas as gpd
from shapely import wkt
import pyarrow as pa
import pyarrow.parquet as pq

def main():
    input_file = "nyc_addresses.csv"
    output_file = "addresses.geoparquet"

    print(f"Reading {input_file}...")
    df = pd.read_csv(input_file)

    print("Converting geometry...")
    # Convert WKT to geometry
    df['geometry'] = df['geometry_wkt'].apply(wkt.loads)
    
    # Convert to GeoDataFrame
    gdf = gpd.GeoDataFrame(df, geometry='geometry', crs="EPSG:4326")

    print("Processing columns...")
    # 1. recorded_at as timestamp[us]
    gdf['recorded_at'] = pd.to_datetime(gdf['recorded_at']).dt.tz_localize(None)
    
    # 2. unit_count as int32
    gdf['unit_count'] = gdf['unit_count'].astype('int32')

    # 3. All other columns as string
    # Identify columns that are not geometry, recorded_at, or unit_count
    cols_to_stringify = [col for col in gdf.columns if col not in ['geometry', 'recorded_at', 'unit_count']]
    for col in cols_to_stringify:
        gdf[col] = gdf[col].astype(str)

    # Reorder/Clean up: Remove the original wkt column if it exists
    if 'geometry_wkt' in gdf.columns:
        gdf = gdf.drop(columns=['geometry_wkt'])

    print(f"Writing to {output_file}...")
    # GeoParquet writing via geopandas/pyarrow
    # We want to ensure the types are strictly enforced in the parquet schema
    gdf.to_parquet(output_file, index=False)

    # Verify the schema
    print("Verifying schema...")
    table = pq.read_table(output_file)
    print("Schema:")
    print(table.schema)
    
    # Check data types of a few columns
    print("\nColumn types in Parquet:")
    for field in table.schema:
        print(f"{field.name}: {field.type}")

if __name__ == "__main__":
    main()
Wrote /work/solve.py (1873 chars).
0:23
Bash uv run solve.py
Reading nyc_addresses.csv...
Converting geometry...
Processing columns...
Writing to addresses.geoparquet...
Verifying schema...
Schema:
id: large_string
country: large_string
postcode: large_string
street: large_string
number: large_string
unit: large_string
postal_city: large_string
recorded_at: timestamp[us]
unit_count: int32
geometry: binary
  -- field metadata --
  ARROW:extension:name: 'geoarrow.wkb'
  ARROW:extension:metadata: '{"crs": {"$schema": "https://proj.org/schema' + 1498
-- schema metadata --
pandas: '{"index_columns": [], "column_indexes": [], "columns": [{"name":' + 1215
geo: '{"primary_column": "geometry", "columns": {"geometry": {"encoding":' + 1373

Column types in Parquet:
id: large_string
country: large_string
postcode: large_string
street: large_string
number: large_string
unit: large_string
postal_city: large_string
recorded_at: timestamp[us]
unit_count: int32
geometry: binary
Installed 11 packages in 596ms
0:34
Bash ls -F
addresses.geoparquet
nyc_addresses.csv
solve.py
0:44