Skip to content

fix: keep columns that share a title instead of overwriting them - #5

Merged
thomaspinder merged 1 commit into
mainfrom
fix/duplicate-column-titles
Oct 21, 2026
Merged

thomaspinder merged 1 commit into
mainfrom
fix/duplicate-column-titles

Conversation

@thomaspinder

Copy link
Copy Markdown
Collaborator

Summary

get_data named each column by its CBS title. When two columns share a title, the later one overwrote the earlier without any warning. 85592NED (consumer energy prices) has six titles that appear under both Aardgas and Elektriciteit, so all six gas columns came back holding electricity values. columns= had the same collision: columns=["Transporttarief"] quietly selected the electricity column.

 get_data(table)
-  column_map = {key: title}                      # shared titles collide
+  column_map = _column_names(props)
+    shared title -> "<topic group>: <title>"     # "Aardgas: Transporttarief"
+    still shared -> "<title> (<key>)"            # "Totaal (Totaal_1)"
   if columns:
+    a shared bare title raises ValueError listing the qualified names

Titles that aren't shared are unchanged, so existing column names stay the same. The getting-started docs now describe the rule.

Evidence

  • Before: get_data("85592NED") returns 11 columns, and Transporttarief holds 394.11 €/yr, which is the electricity tariff.
    After: it returns 17 columns, with Aardgas: Transporttarief = 221.79 and Elektriciteit: Transporttarief = 394.11. Both match the raw OData values (Transporttarief_1, Transporttarief_7) for September 2026, excluding VAT.
  • After: get_data("85592NED", columns=["Transporttarief"]) raises ValueError: 'Transporttarief' is the title of several columns in 85592NED; use one of ['Aardgas: Transporttarief', 'Elektriciteit: Transporttarief'].
  • New tests in TestGetDataDuplicateTitles, all four failing on main and passing here:
    • test_shared_titles_are_qualified_by_group
    • test_shared_titles_without_group_fall_back_to_key
    • test_columns_accepts_qualified_title
    • test_columns_rejects_shared_title
  • All 57 tests pass. ruff check, ruff format --check and ty check are clean.

Merge Danger

Door: two-way

Blast Radius: column names

  • In tables with shared titles, column names change: Transporttarief becomes Aardgas: Transporttarief / Elektriciteit: Transporttarief. Code that indexed the bare name breaks with a ColumnNotFoundError. It was reading the wrong series before, so failing loudly is the intended outcome.
  • columns= with a shared bare title now raises rather than picking one.
  • An empty result no longer contains a stray column named after the last topic group. Topic groups have an empty key and are no longer treated as columns.

🤖 Generated with Claude Code

get_data keyed renamed columns by title, so when two columns share a
title (85592NED has "Transporttarief" under both Aardgas and
Elektriciteit) the later one silently replaced the earlier: the gas
tariff columns came back holding electricity values. columns= had the
same collision and selected the electricity column.

Shared titles are now prefixed with their topic group, falling back to
the CBS key, and columns= raises on a shared title rather than guessing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@thomaspinder
thomaspinder merged commit f89859d into main Oct 21, 2026
7 checks passed
@thomaspinder
thomaspinder deleted the fix/duplicate-column-titles branch October 21, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants