fix([2fd88f42]): handle malformed header in PLZ csv dataset

This commit is contained in:
2026-02-04 13:03:12 +00:00
parent d9eef04732
commit e006fcfa17

View File

@@ -26,13 +26,19 @@ def load_plz_data():
global plz_geocoord_df
try:
print("--- Loading PLZ geocoordinates dataset... ---")
df = pd.read_csv("plz_geocoord.csv", dtype={'plz': str})
# The CSV has a malformed header. We read it and assign names manually.
df = pd.read_csv("plz_geocoord.csv", dtype=str)
# Rename the columns based on their expected order: PLZ, Latitude, Longitude
df.columns = ['plz', 'y', 'x']
df['plz'] = df['plz'].str.zfill(5)
plz_geocoord_df = df.set_index('plz')
print(f"--- Successfully loaded {len(plz_geocoord_df)} PLZ coordinates. ---")
except FileNotFoundError:
print("--- FATAL ERROR: plz_geocoord.csv not found. Geocoding will not work. ---")
# In a real app, you might want to exit or handle this more gracefully
plz_geocoord_df = pd.DataFrame()
except Exception as e:
print(f"--- FATAL ERROR loading plz_geocoord.csv: {e} ---")
plz_geocoord_df = pd.DataFrame()
# --- Pydantic Models ---