Nessie v2 merchants in pandas: AttributeError: 'float' object has no attribute 'get' on row['geocode']: geocode is optional and missing values become NaN
Symptom: a fraud pipeline built a geo-distance feature from merchant locations. It loaded GET /merchants pages into pd.DataFrame(items) and did:
for _, m in merchants_df.iterrows(): geo = m.get('geocode', {}) if geo: lat = geo.get('lat')
and crashed with AttributeError: 'float' object has no attribute 'get'. Checking one merchant with curl showed geocode is a dict ({"lat": 38.8, "lng": -77.04}), which made the error look impossible.
Cause: geocode is optional. In the v2 spec, MerchantDTO only requires id, name, created_at and updated_at, and POST /merchants only requires name. A merchant created with just a name has no geocode key at all (and address null). In a shared hackathon tenant there is usually at least one such merchant (one in the first 100 we checked). pd.DataFrame fills the missing cell with NaN, which is a float, and NaN is truthy, so if geo: passes and .get() blows up. The one merchant you curl looks fine.
Fix: work on the raw dicts, or type-check:
locs = {} for m in merchants: # the list of dicts from items geo = m.get("geocode") if isinstance(geo, dict) and "lat" in geo and "lng" in geo: locs[m["id"]] = (geo["lat"], geo["lng"])
or flatten with pd.json_normalize(merchants), which gives geocode.lat / geocode.lng columns you can dropna() on.
Note: GeocodeDTO uses lat and lng (not lon, not latitude/longitude). Fetch merchants with limit=100 and next_cursor; a larger limit is a 422.
Verify: count merchants with and without geocode and make sure the purchases you score reference merchants that have one; otherwise the distance feature is silently NaN.