Skip to content

open-mastr doesn't translate category number to string value for columns where XSD doesn't markt the column as a restriction #769

Description

@Simon-Will

Description of the issue

When using Mastr().download(bulk_cleansing=True), I expect all catalog category values to be translated from the integer in the XML to the corresponding string in Katalogkategorien.xml. This doesn't work corretly for some columns:

  • Netze.xml: Marktgebiet, Bundesland, Sparte
  • EinheitenWind.xml: Hersteller
  • Marktakteure.xml: Rechtsform, Registergericht

These are the ones I identified right now based on some heuristics. Maybe there are more that could be found from the values (cf. solution idea 3 below

Steps to Reproduce

  1. Run Mastr().download(bulk_cleansing=True)
  2. Query e.g. select distinct Sparte from Netze;. It results in [20, 21], while the desired result is ["Strom", "Gas"].

Ideas of solution

  1. Ask BNetzA to fix their XSDs so that all catalog category columns are properly marked as <xs:restriction base="xs:short"> (short can also be int or byte)
  2. In open-mastr, check the name of columns and compare them with the category names from Katalogkategorien.xml. If a column name has a match in the category names, treat the column as a category column. The matching cannot be made super strict because the category names sometimes have spelling errors ( Solaranlaege Anlagentyp) and the matching is often only rough e.g. column TechnologieFlugwindenergieanlagefromEinheitenWind.xmlbelongs to categoryTechnologie (Flugwind)`
  3. We could also try to determine if it's a category from the value that we find in a column. If we only find integers (or comma-separated lists of integers), and many integers occur multiple times, then it's likely that it's a category column. The problem with this approach is that we want to get the table definitions from the XSDs, not the values in the XML files. It would complicate the current approach. And it's also a bit annoying to code.

Context and Environment

  • Version used: Unreleased 73d1a3d
  • Operating system: Doesn't matter
  • Environment setup and (python) version: Doesn't matter
  • MaStR version: 20260715

Workflow checklist

Metadata

Metadata

Assignees

Labels

🐛 bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions