mloda-plugin-govdata 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mloda_plugin_govdata-0.4.0/PKG-INFO +143 -0
- mloda_plugin_govdata-0.4.0/README.md +101 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/cache.py +10 -3
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/period.py +11 -6
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/reader.py +8 -2
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py +4 -9
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/discovery.py +8 -5
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/locator.py +4 -1
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/provenance.py +3 -3
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/population.py +2 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/reader.py +30 -8
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/uba.py +39 -14
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/base.py +5 -11
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/sources.py +8 -9
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/period.py +2 -3
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/rebase.py +3 -4
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/land_population_per_voter.py +9 -6
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/write.py +7 -1
- mloda_plugin_govdata-0.4.0/mloda_plugin_govdata.egg-info/PKG-INFO +143 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata.egg-info/requires.txt +4 -2
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/pyproject.toml +5 -4
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/tests/test_capture_genesis_fixtures.py +48 -20
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/tests/test_demo_definition.py +31 -5
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/tests/test_land_join.py +44 -8
- mloda_plugin_govdata-0.3.0/PKG-INFO +0 -203
- mloda_plugin_govdata-0.3.0/README.md +0 -163
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata.egg-info/PKG-INFO +0 -203
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/LICENSE +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/NOTICE.md +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/conftest.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/api.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/auth.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/envelope.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/errors.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/hosts.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/parse.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/core/redact.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/destatis/locator.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/cache.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/client.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/core/parse.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/govdata/feature.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/crosswalk.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/keys.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/land_codes.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/nuts.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/rebase.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/bbsr.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/download.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/eurostat.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/core/reference/gv_isys.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/feature_groups/harmonization/nuts.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/__init__.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/credential_scan.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/frames.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/load.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata/recipes/model.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata.egg-info/SOURCES.txt +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata.egg-info/dependency_links.txt +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/mloda_plugin_govdata.egg-info/top_level.txt +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/setup.cfg +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/tests/test_mloda_imports.py +0 -0
- {mloda_plugin_govdata-0.3.0 → mloda_plugin_govdata-0.4.0}/tests/test_packaging.py +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mloda-plugin-govdata
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: mloda plugin providing connectors, harmonization and recipes for German government data (GovData.de CKAN API, Destatis GENESIS webservice).
|
|
5
|
+
Author-email: Tom Kaltofen <tomkaltofen@mloda.ai>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/mloda-ai/mloda-plugin-govdata
|
|
8
|
+
Project-URL: Repository, https://github.com/mloda-ai/mloda-plugin-govdata
|
|
9
|
+
Project-URL: Issues, https://github.com/mloda-ai/mloda-plugin-govdata/issues
|
|
10
|
+
Project-URL: Releases, https://github.com/mloda-ai/mloda-plugin-govdata/releases
|
|
11
|
+
Project-URL: Prototype Fund, https://www.prototypefund.de/projects/mloda-plugin-govdata
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
License-File: NOTICE.md
|
|
16
|
+
Requires-Dist: mloda<0.16.0,>=0.15.1
|
|
17
|
+
Requires-Dist: filelock>=3.12
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Requires-Dist: openpyxl>=3.1
|
|
20
|
+
Requires-Dist: pandas>=2.0
|
|
21
|
+
Requires-Dist: pyarrow>=17.0
|
|
22
|
+
Requires-Dist: pydantic>=2.0
|
|
23
|
+
Requires-Dist: tenacity>=8.0
|
|
24
|
+
Provides-Extra: demo
|
|
25
|
+
Requires-Dist: marimo>=0.14; extra == "demo"
|
|
26
|
+
Requires-Dist: altair>=5; extra == "demo"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mloda-testing>=0.9.0; extra == "dev"
|
|
29
|
+
Requires-Dist: tox; extra == "dev"
|
|
30
|
+
Requires-Dist: tox-uv; extra == "dev"
|
|
31
|
+
Requires-Dist: uv>=0.11.15; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy; extra == "dev"
|
|
35
|
+
Requires-Dist: bandit; extra == "dev"
|
|
36
|
+
Requires-Dist: hypothesis; extra == "dev"
|
|
37
|
+
Requires-Dist: packaging>=24.2; extra == "dev"
|
|
38
|
+
Requires-Dist: respx; extra == "dev"
|
|
39
|
+
Requires-Dist: pandas-stubs; extra == "dev"
|
|
40
|
+
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/LICENSE)
|
|
44
|
+
[](https://github.com/mloda-ai/mloda)
|
|
45
|
+
[](https://www.python.org/)
|
|
46
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/actions/workflows/test.yml?query=branch%3Amain)
|
|
47
|
+
[](https://prototypefund.de)
|
|
48
|
+
|
|
49
|
+
# mloda-plugin-govdata
|
|
50
|
+
|
|
51
|
+
German open government data as typed tables you can trust: found, downloaded, parsed, made comparable, and traceable to its source. A plugin for [mloda](https://github.com/mloda-ai/mloda): you name the columns, it does the rest.
|
|
52
|
+
|
|
53
|
+
## Why
|
|
54
|
+
|
|
55
|
+
The data is open, but every team rewrites the same scripts:
|
|
56
|
+
|
|
57
|
+
- **German CSV.** Decimal commas, multi-row headers, and signs like `-` and `.` that mean different things.
|
|
58
|
+
- **Changing borders.** Göttingen and Osterode merged in 2016. The raw Destatis table shows three districts, and zeros for the years each one did not exist.
|
|
59
|
+
- **Lost provenance.** Which file, which license, which attribution: gone by the time the chart is done.
|
|
60
|
+
|
|
61
|
+
## What's inside
|
|
62
|
+
|
|
63
|
+
| | |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| **Sources** | GovData.de, Destatis GENESIS (GENESIS-Online, Regionalstatistik), Bundeswahlleiterin election results, UBA air quality |
|
|
66
|
+
| **Harmonization** | district series on today's borders, NUTS codes for German region keys, typed years |
|
|
67
|
+
| **Recipes** | JSON files that pin the features, joins, source, license, and checksum of one result |
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install mloda-plugin-govdata
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Quick start
|
|
76
|
+
|
|
77
|
+
No account needed for GovData:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from mloda.user import Feature, mloda
|
|
81
|
+
from mloda_plugin_govdata.feature_groups.govdata import StuttgartPopulationReader
|
|
82
|
+
|
|
83
|
+
slug = "einwohner-nach-altersgruppen-und-stadtbezirken"
|
|
84
|
+
result = mloda.run_all(
|
|
85
|
+
[Feature("Einwohner", options={StuttgartPopulationReader: slug})],
|
|
86
|
+
compute_frameworks=["PyArrowTable"],
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Destatis, with a free [GENESIS account](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/credentials.md):
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from mloda_plugin_govdata.feature_groups.destatis import DestatisReader
|
|
94
|
+
|
|
95
|
+
result = mloda.run_all(
|
|
96
|
+
[Feature("value", options={DestatisReader: "12411-0010"})], # population by Land
|
|
97
|
+
compute_frameworks=["PyArrowTable"],
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Göttingen on today's borders, with `value__rebased` ([full example](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/harmonization.md#usage)):
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
~key ~year ~value ~flag ~sources
|
|
105
|
+
03159 2013 322616.0 rebased [03152, 03156]
|
|
106
|
+
03159 2015 329538.0 rebased [03152, 03156]
|
|
107
|
+
03159 2016 327065.0 observed []
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Demo
|
|
111
|
+
|
|
112
|
+
A [marimo](https://marimo.io) notebook walks through every source, the Göttingen series, and a join of population and eligible voters for all 16 Länder:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
git clone https://github.com/mloda-ai/mloda-plugin-govdata.git
|
|
116
|
+
cd mloda-plugin-govdata
|
|
117
|
+
uv sync --all-extras
|
|
118
|
+
uv run marimo edit demos/govdata_demo.py
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The Destatis chapters skip themselves without GENESIS credentials. A second notebook, `demos/berlin_wahl_2026_demo.py`, reads four Berlin elections with one set of reader options.
|
|
122
|
+
|
|
123
|
+
## Docs
|
|
124
|
+
|
|
125
|
+
- [Readers](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/readers.md): every source, dataset search, `peek`
|
|
126
|
+
- [Destatis options](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/destatis-options.md) and [credentials](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/credentials.md)
|
|
127
|
+
- [Harmonization](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/harmonization.md)
|
|
128
|
+
- [Recipes](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/recipes.md)
|
|
129
|
+
- [Architecture](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/architecture.md) and [adding a reader](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/adding-a-reader.md)
|
|
130
|
+
|
|
131
|
+
## Status
|
|
132
|
+
|
|
133
|
+
Young but working, built during a Prototype Fund stage (June to November 2026). The API may still change; the [release notes](https://github.com/mloda-ai/mloda-plugin-govdata/releases) give a migration for every breaking change.
|
|
134
|
+
|
|
135
|
+
## Funding
|
|
136
|
+
|
|
137
|
+
Funded by the German Federal Ministry of Research, Technology and Space (BMFTR) through the [Prototype Fund](https://prototypefund.de), supported by the [Open Knowledge Foundation Deutschland](https://okfn.de). Funding code: **16IS26S11**.
|
|
138
|
+
|
|
139
|
+
<p>
|
|
140
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/bmftr.png" alt="Funded by the Federal Ministry of Research, Technology and Space (BMFTR)" height="110">
|
|
141
|
+
|
|
142
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/prototypefund.png" alt="Supported by the Prototype Fund" height="110">
|
|
143
|
+
</p>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/LICENSE)
|
|
2
|
+
[](https://github.com/mloda-ai/mloda)
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/actions/workflows/test.yml?query=branch%3Amain)
|
|
5
|
+
[](https://prototypefund.de)
|
|
6
|
+
|
|
7
|
+
# mloda-plugin-govdata
|
|
8
|
+
|
|
9
|
+
German open government data as typed tables you can trust: found, downloaded, parsed, made comparable, and traceable to its source. A plugin for [mloda](https://github.com/mloda-ai/mloda): you name the columns, it does the rest.
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
The data is open, but every team rewrites the same scripts:
|
|
14
|
+
|
|
15
|
+
- **German CSV.** Decimal commas, multi-row headers, and signs like `-` and `.` that mean different things.
|
|
16
|
+
- **Changing borders.** Göttingen and Osterode merged in 2016. The raw Destatis table shows three districts, and zeros for the years each one did not exist.
|
|
17
|
+
- **Lost provenance.** Which file, which license, which attribution: gone by the time the chart is done.
|
|
18
|
+
|
|
19
|
+
## What's inside
|
|
20
|
+
|
|
21
|
+
| | |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| **Sources** | GovData.de, Destatis GENESIS (GENESIS-Online, Regionalstatistik), Bundeswahlleiterin election results, UBA air quality |
|
|
24
|
+
| **Harmonization** | district series on today's borders, NUTS codes for German region keys, typed years |
|
|
25
|
+
| **Recipes** | JSON files that pin the features, joins, source, license, and checksum of one result |
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install mloda-plugin-govdata
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
No account needed for GovData:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from mloda.user import Feature, mloda
|
|
39
|
+
from mloda_plugin_govdata.feature_groups.govdata import StuttgartPopulationReader
|
|
40
|
+
|
|
41
|
+
slug = "einwohner-nach-altersgruppen-und-stadtbezirken"
|
|
42
|
+
result = mloda.run_all(
|
|
43
|
+
[Feature("Einwohner", options={StuttgartPopulationReader: slug})],
|
|
44
|
+
compute_frameworks=["PyArrowTable"],
|
|
45
|
+
)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Destatis, with a free [GENESIS account](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/credentials.md):
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from mloda_plugin_govdata.feature_groups.destatis import DestatisReader
|
|
52
|
+
|
|
53
|
+
result = mloda.run_all(
|
|
54
|
+
[Feature("value", options={DestatisReader: "12411-0010"})], # population by Land
|
|
55
|
+
compute_frameworks=["PyArrowTable"],
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Göttingen on today's borders, with `value__rebased` ([full example](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/harmonization.md#usage)):
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
~key ~year ~value ~flag ~sources
|
|
63
|
+
03159 2013 322616.0 rebased [03152, 03156]
|
|
64
|
+
03159 2015 329538.0 rebased [03152, 03156]
|
|
65
|
+
03159 2016 327065.0 observed []
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Demo
|
|
69
|
+
|
|
70
|
+
A [marimo](https://marimo.io) notebook walks through every source, the Göttingen series, and a join of population and eligible voters for all 16 Länder:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git clone https://github.com/mloda-ai/mloda-plugin-govdata.git
|
|
74
|
+
cd mloda-plugin-govdata
|
|
75
|
+
uv sync --all-extras
|
|
76
|
+
uv run marimo edit demos/govdata_demo.py
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The Destatis chapters skip themselves without GENESIS credentials. A second notebook, `demos/berlin_wahl_2026_demo.py`, reads four Berlin elections with one set of reader options.
|
|
80
|
+
|
|
81
|
+
## Docs
|
|
82
|
+
|
|
83
|
+
- [Readers](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/readers.md): every source, dataset search, `peek`
|
|
84
|
+
- [Destatis options](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/destatis-options.md) and [credentials](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/credentials.md)
|
|
85
|
+
- [Harmonization](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/harmonization.md)
|
|
86
|
+
- [Recipes](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/recipes.md)
|
|
87
|
+
- [Architecture](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/architecture.md) and [adding a reader](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/adding-a-reader.md)
|
|
88
|
+
|
|
89
|
+
## Status
|
|
90
|
+
|
|
91
|
+
Young but working, built during a Prototype Fund stage (June to November 2026). The API may still change; the [release notes](https://github.com/mloda-ai/mloda-plugin-govdata/releases) give a migration for every breaking change.
|
|
92
|
+
|
|
93
|
+
## Funding
|
|
94
|
+
|
|
95
|
+
Funded by the German Federal Ministry of Research, Technology and Space (BMFTR) through the [Prototype Fund](https://prototypefund.de), supported by the [Open Knowledge Foundation Deutschland](https://okfn.de). Funding code: **16IS26S11**.
|
|
96
|
+
|
|
97
|
+
<p>
|
|
98
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/bmftr.png" alt="Funded by the Federal Ministry of Research, Technology and Space (BMFTR)" height="110">
|
|
99
|
+
|
|
100
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/prototypefund.png" alt="Supported by the Prototype Fund" height="110">
|
|
101
|
+
</p>
|
|
@@ -36,19 +36,26 @@ _SHA256 = re.compile(r"[0-9a-f]{64}")
|
|
|
36
36
|
|
|
37
37
|
# Comma-separated selections the server treats as sets: sorted for the key and on the wire.
|
|
38
38
|
SELECTION_FIELDS: frozenset[str] = frozenset({"regionalkey", *CLASSIFYING_KEYS})
|
|
39
|
+
# Numeric fields; anywhere else an int would drop a code's leading zeros.
|
|
40
|
+
_INT_FIELDS: frozenset[str] = frozenset({"startyear", "endyear", "timeslices"})
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
def _wire_scalar(name: str, value: object) -> str:
|
|
42
|
-
"""One value as it travels: strings stripped, ints as digits; bools refused."""
|
|
44
|
+
"""One value as it travels: strings stripped, ints as digits (``_INT_FIELDS`` only); bools refused."""
|
|
43
45
|
if isinstance(value, bool):
|
|
44
46
|
# The spec spells booleans per field ("true"/"false" for compress, "on"/"off" for quality).
|
|
45
47
|
raise TypeError(f"parameter {name!r}: pass the wire string for booleans, not a bool")
|
|
46
48
|
if isinstance(value, int):
|
|
47
|
-
|
|
49
|
+
if name in _INT_FIELDS:
|
|
50
|
+
return str(value)
|
|
51
|
+
raise TypeError(f"parameter {name!r} must be a str: an int loses a code's leading zeros")
|
|
48
52
|
if isinstance(value, str):
|
|
49
53
|
return value.strip()
|
|
50
54
|
# Named by field only: a value could be a secret pasted into the wrong place.
|
|
51
|
-
raise TypeError(
|
|
55
|
+
raise TypeError(
|
|
56
|
+
f"parameter {name!r} must be a str (an int for {', '.join(sorted(_INT_FIELDS))}) "
|
|
57
|
+
f"or a flat sequence of those, got {type(value).__name__}"
|
|
58
|
+
)
|
|
52
59
|
|
|
53
60
|
|
|
54
61
|
def canonical_parameters(endpoint: str, parameters: Mapping[str, object]) -> dict[str, str]:
|
|
@@ -4,7 +4,8 @@ GENESIS annual tables carry two labels for the same annual granularity: JAHR
|
|
|
4
4
|
(a plain year, ``"2015"``) and STAG (a 31 Dec reference date, ``"2015-12-31"``
|
|
5
5
|
or ``"31.12.2015"``). Both normalize to the same annual :class:`Period`; only
|
|
6
6
|
the year matters, not which label produced it. kerg has no time column, the
|
|
7
|
-
election date comes from the locator or recipe (:func:`from_snapshot`)
|
|
7
|
+
election date comes from the locator or recipe (:func:`from_snapshot`); the
|
|
8
|
+
Destatis Stichtag a snapshot joins to is :func:`stichtag_period`.
|
|
8
9
|
Quarter and month parsing are not built:
|
|
9
10
|
:class:`Frequency` keeps all three values for forward compatibility, but only
|
|
10
11
|
``year`` has a working parser.
|
|
@@ -85,11 +86,9 @@ def _annual_stag(label: str, *, year: int, month: int, day: int) -> Period:
|
|
|
85
86
|
def from_snapshot(snapshot: date, freq: Frequency = Frequency.YEAR) -> Period:
|
|
86
87
|
"""Builds a :class:`Period` from a point-in-time snapshot (e.g. an election date).
|
|
87
88
|
|
|
88
|
-
Floors to the calendar year containing ``snapshot
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
join plumbing. Only ``Frequency.YEAR`` is implemented; quarter and
|
|
92
|
-
month raise ``NotImplementedError``.
|
|
89
|
+
Floors to the calendar year containing ``snapshot``: the snapshot's own year,
|
|
90
|
+
not the Destatis year it joins to (that is :func:`stichtag_period`). Only
|
|
91
|
+
``Frequency.YEAR`` is implemented; quarter and month raise ``NotImplementedError``.
|
|
93
92
|
"""
|
|
94
93
|
freq = Frequency(freq)
|
|
95
94
|
if freq is not Frequency.YEAR:
|
|
@@ -97,6 +96,12 @@ def from_snapshot(snapshot: date, freq: Frequency = Frequency.YEAR) -> Period:
|
|
|
97
96
|
return Period(date(snapshot.year, 1, 1), freq)
|
|
98
97
|
|
|
99
98
|
|
|
99
|
+
def stichtag_period(snapshot: date) -> Period:
|
|
100
|
+
"""The annual period of the last 31 Dec Stichtag on or before ``snapshot`` (the join year for an election)."""
|
|
101
|
+
year = snapshot.year if (snapshot.month, snapshot.day) == (12, 31) else snapshot.year - 1
|
|
102
|
+
return Period(date(year, 1, 1), Frequency.YEAR)
|
|
103
|
+
|
|
104
|
+
|
|
100
105
|
def assert_same_frequency(left: Period, right: Period) -> None:
|
|
101
106
|
"""Raises ``ValueError`` naming both frequencies on a mismatch. No implicit aggregation."""
|
|
102
107
|
if left.freq is not right.freq:
|
|
@@ -11,12 +11,13 @@ from __future__ import annotations
|
|
|
11
11
|
|
|
12
12
|
import functools
|
|
13
13
|
from pathlib import Path
|
|
14
|
-
from typing import Any
|
|
14
|
+
from typing import Any, ClassVar
|
|
15
15
|
|
|
16
16
|
import pyarrow as pa
|
|
17
17
|
from mloda.provider import CHAIN_SEPARATOR, COLUMN_SEPARATOR
|
|
18
18
|
from mloda.user import Options
|
|
19
19
|
|
|
20
|
+
from ..govdata.core.discovery import DL_DE_BY_2_0
|
|
20
21
|
from ..govdata.core.provenance import FetchedPayload, Provenance
|
|
21
22
|
from ..govdata.reader import BaseGovDataReader
|
|
22
23
|
from .core.api import GenesisClient, fetch_tablefile
|
|
@@ -30,6 +31,9 @@ from .locator import DestatisLocator
|
|
|
30
31
|
class DestatisReader(BaseGovDataReader[DestatisLocator]):
|
|
31
32
|
"""Reads one GENESIS table selection into a typed Arrow table, ffcsv parsed."""
|
|
32
33
|
|
|
34
|
+
# The reader resolves only the known GENESIS hosts, and both publish under DL-DE-BY-2.0.
|
|
35
|
+
LICENSE: ClassVar[str | None] = DL_DE_BY_2_0
|
|
36
|
+
|
|
33
37
|
@classmethod
|
|
34
38
|
def suffix(cls) -> tuple[str, ...]:
|
|
35
39
|
return (".zip",)
|
|
@@ -58,7 +62,9 @@ class DestatisReader(BaseGovDataReader[DestatisLocator]):
|
|
|
58
62
|
with GenesisClient(host, credentials=explicit, lock_dir=cls.cache_dir) as client:
|
|
59
63
|
fetch = functools.partial(fetch_tablefile, client)
|
|
60
64
|
cached = cache.get_or_fetch(host, "data/tablefile", fields, fetch)
|
|
61
|
-
provenance = Provenance(
|
|
65
|
+
provenance = Provenance(
|
|
66
|
+
source="genesis", url=host.url("data/tablefile"), parameters=cached.parameters, license=cls.LICENSE
|
|
67
|
+
)
|
|
62
68
|
return FetchedPayload(
|
|
63
69
|
path=cached.path, sha256=cached.sha256, retrieved_at=cached.retrieved_at, provenance=provenance
|
|
64
70
|
)
|
|
@@ -49,37 +49,32 @@ class BundeswahlleiterinReader(BaseGovDataReader[GovDataLocator]):
|
|
|
49
49
|
"Preamble lines to skip before the header block.",
|
|
50
50
|
default=5,
|
|
51
51
|
strict_validation=True,
|
|
52
|
+
scalar_only=True,
|
|
52
53
|
element_validator=_is_non_negative_int,
|
|
53
54
|
),
|
|
54
55
|
OPTION_WAHL_HEADER_ROWS: PropertySpec(
|
|
55
56
|
"Merged header rows flattened into column names.",
|
|
56
57
|
default=3,
|
|
57
58
|
strict_validation=True,
|
|
59
|
+
scalar_only=True,
|
|
58
60
|
element_validator=is_positive_int,
|
|
59
61
|
),
|
|
60
62
|
OPTION_WAHL_LABEL_COLUMNS: PropertySpec(
|
|
61
63
|
"Leading columns typed as strings, not value_type.",
|
|
62
64
|
default=4,
|
|
63
65
|
strict_validation=True,
|
|
66
|
+
scalar_only=True,
|
|
64
67
|
element_validator=_is_non_negative_int,
|
|
65
68
|
),
|
|
66
69
|
OPTION_WAHL_VALUE_TYPE: PropertySpec(
|
|
67
70
|
"ColumnType of the non-label columns.",
|
|
68
71
|
default=ColumnType.INTEGER,
|
|
69
72
|
strict_validation=True,
|
|
73
|
+
scalar_only=True,
|
|
70
74
|
allowed_values=tuple(ColumnType),
|
|
71
75
|
),
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
@classmethod
|
|
75
|
-
def match_subclass_data_access(cls, data_access: Any, feature_names: list[str], options: Any) -> Any:
|
|
76
|
-
locator = super().match_subclass_data_access(data_access, feature_names, options)
|
|
77
|
-
if locator is None:
|
|
78
|
-
return None
|
|
79
|
-
for key in cls.READER_OPTIONS:
|
|
80
|
-
cls._scalar_reader_option(key, options)
|
|
81
|
-
return locator
|
|
82
|
-
|
|
83
78
|
@classmethod
|
|
84
79
|
def _parse(cls, path: Path, locator: GovDataLocator, *, options: Options | None = None) -> pa.Table:
|
|
85
80
|
return parse_multi_header_csv(
|
|
@@ -12,13 +12,16 @@ from pydantic import BaseModel, ConfigDict
|
|
|
12
12
|
from .client import request_with_retry
|
|
13
13
|
from .locator import DEFAULT_CKAN_BASE, GovDataLocator
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
CC_BY_4_0 = "CC-BY-4.0"
|
|
16
|
+
DL_DE_BY_2_0 = "DL-DE-BY-2.0"
|
|
17
|
+
|
|
18
|
+
# dcat-ap.de license URIs observed across GovData distributions -> SPDX ids, LicenseRef- where SPDX has none.
|
|
16
19
|
LICENSE_LABELS: dict[str, str] = {
|
|
17
|
-
"http://dcat-ap.de/def/licenses/cc-by/4.0":
|
|
18
|
-
"http://dcat-ap.de/def/licenses/dl-by-de/2.0":
|
|
19
|
-
"http://dcat-ap.de/def/licenses/dl-zero-de/2.0": "DL-DE-
|
|
20
|
+
"http://dcat-ap.de/def/licenses/cc-by/4.0": CC_BY_4_0,
|
|
21
|
+
"http://dcat-ap.de/def/licenses/dl-by-de/2.0": DL_DE_BY_2_0,
|
|
22
|
+
"http://dcat-ap.de/def/licenses/dl-zero-de/2.0": "DL-DE-ZERO-2.0",
|
|
20
23
|
"http://dcat-ap.de/def/licenses/cc-zero": "CC0-1.0",
|
|
21
|
-
"http://dcat-ap.de/def/licenses/geonutz/20130319": "GeoNutzV",
|
|
24
|
+
"http://dcat-ap.de/def/licenses/geonutz/20130319": "LicenseRef-GeoNutzV",
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
|
|
@@ -12,7 +12,10 @@ _L = TypeVar("_L", bound="Locator")
|
|
|
12
12
|
|
|
13
13
|
@runtime_checkable
|
|
14
14
|
class Locator(Protocol):
|
|
15
|
-
"""What a reader needs from its locator type: coercion from an option value and a label
|
|
15
|
+
"""What a reader needs from its locator type: coercion from an option value and a label.
|
|
16
|
+
|
|
17
|
+
The label names the dataset in messages and in lineage and audit records, so it never carries a credential.
|
|
18
|
+
"""
|
|
16
19
|
|
|
17
20
|
# PYI019 wants `Self`, which is 3.11+; the package floor is 3.10.
|
|
18
21
|
@classmethod
|
|
@@ -21,12 +21,12 @@ class Provenance:
|
|
|
21
21
|
dataset: Dataset | None = None
|
|
22
22
|
|
|
23
23
|
@classmethod
|
|
24
|
-
def from_distribution(cls, distribution: ResolvedDistribution) -> Provenance:
|
|
25
|
-
"""``ckan`` when discovery ran, ``url`` for a direct distribution."""
|
|
24
|
+
def from_distribution(cls, distribution: ResolvedDistribution, default_license: str | None = None) -> Provenance:
|
|
25
|
+
"""``ckan`` when discovery ran, ``url`` for a direct distribution; ``default_license`` when it reports none."""
|
|
26
26
|
return cls(
|
|
27
27
|
source="ckan" if distribution.dataset is not None else "url",
|
|
28
28
|
url=distribution.url,
|
|
29
|
-
license=distribution.license,
|
|
29
|
+
license=distribution.license or default_license,
|
|
30
30
|
dataset=distribution.dataset,
|
|
31
31
|
)
|
|
32
32
|
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import ClassVar
|
|
6
6
|
|
|
7
|
+
from .core.discovery import CC_BY_4_0
|
|
7
8
|
from .core.parse import ColumnType
|
|
8
9
|
from .reader import GovDataReader
|
|
9
10
|
|
|
@@ -20,3 +21,4 @@ class StuttgartPopulationReader(GovDataReader):
|
|
|
20
21
|
"""Residents by age group and city district, with typed columns."""
|
|
21
22
|
|
|
22
23
|
schema: ClassVar[dict[str, ColumnType] | None] = POPULATION_SCHEMA
|
|
24
|
+
LICENSE: ClassVar[str | None] = CC_BY_4_0
|
|
@@ -9,12 +9,13 @@ the cache, parse it into a typed Arrow table. One module per data source impleme
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
11
|
import difflib
|
|
12
|
+
from collections.abc import Mapping
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
from typing import Any, ClassVar, Generic, TypeVar, cast
|
|
14
15
|
|
|
15
16
|
import pyarrow as pa
|
|
16
17
|
from mloda.provider import FeatureSet
|
|
17
|
-
from mloda.user import Options
|
|
18
|
+
from mloda.user import DataType, Options
|
|
18
19
|
from mloda.user.pyarrow import PyArrowTable # noqa: F401
|
|
19
20
|
from mloda_plugins.feature_group.input_data.read_file import ReadFile
|
|
20
21
|
|
|
@@ -51,6 +52,8 @@ class BaseGovDataReader(ReadFile, Generic[LocatorT]):
|
|
|
51
52
|
|
|
52
53
|
# Persistent, content-addressed cache location (override per environment).
|
|
53
54
|
cache_dir: ClassVar[str] = str(DEFAULT_CACHE_DIR)
|
|
55
|
+
# The one license every payload of this reader carries, as normalize_license labels it; None when it varies.
|
|
56
|
+
LICENSE: ClassVar[str | None] = None
|
|
54
57
|
|
|
55
58
|
@classmethod
|
|
56
59
|
def suffix(cls) -> tuple[str, ...]:
|
|
@@ -97,12 +100,26 @@ class BaseGovDataReader(ReadFile, Generic[LocatorT]):
|
|
|
97
100
|
return {field.name: str(field.type) for field in table.schema}
|
|
98
101
|
|
|
99
102
|
@classmethod
|
|
100
|
-
def
|
|
101
|
-
"""
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
def describe_columns(cls, data_access: Any) -> dict[str, DataType | None]:
|
|
104
|
+
"""``peek`` as mloda's column discovery (lineage extenders call it); downloads through the cache too."""
|
|
105
|
+
table = cls._read_table(cls._coerce_locator(data_access))
|
|
106
|
+
return {field.name: DataType.from_arrow_type_safe(field.type) for field in table.schema}
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def data_access_identity(cls, data_access: Any) -> str:
|
|
110
|
+
"""The dataset name in lineage and audit records: the locator label, a URL cut to scheme, host and path.
|
|
111
|
+
|
|
112
|
+
mloda's default names every locator by its type alone. The selection (years, keys, a URL query) is left out.
|
|
113
|
+
"""
|
|
114
|
+
if not isinstance(data_access, cls.locator_type()):
|
|
115
|
+
return super().data_access_identity(data_access)
|
|
116
|
+
label = data_access.describe()
|
|
117
|
+
return super().data_access_identity(label) if label.startswith(("http://", "https://")) else label
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def declared_attributes(cls, features: FeatureSet | None) -> Mapping[str, str | int | float | bool]:
|
|
121
|
+
"""``license`` for extenders and ``required_declarations``, the same at plan and load time."""
|
|
122
|
+
return {"license": cls.LICENSE} if cls.LICENSE else {}
|
|
106
123
|
|
|
107
124
|
@classmethod
|
|
108
125
|
def _coerce_locator(cls, data_access: Any) -> LocatorT:
|
|
@@ -123,12 +140,17 @@ class BaseGovDataReader(ReadFile, Generic[LocatorT]):
|
|
|
123
140
|
raise NotImplementedError(f"{cls.__name__} must implement _fetch for {type(locator).__name__}")
|
|
124
141
|
with build_client() as client:
|
|
125
142
|
distribution = resolve_distribution(locator, client)
|
|
143
|
+
if cls.LICENSE and distribution.license and distribution.license != cls.LICENSE:
|
|
144
|
+
raise ValueError(
|
|
145
|
+
f"{cls.__name__} declares license {cls.LICENSE!r}, but {locator.describe()!r} is published "
|
|
146
|
+
f"under {distribution.license!r}; read it with a reader that declares no license."
|
|
147
|
+
)
|
|
126
148
|
cached = DownloadCache(cls.cache_dir, client=client).get_or_download(distribution.url)
|
|
127
149
|
return FetchedPayload(
|
|
128
150
|
path=cached.path,
|
|
129
151
|
sha256=cached.sha256,
|
|
130
152
|
retrieved_at=cached.retrieved_at,
|
|
131
|
-
provenance=Provenance.from_distribution(distribution),
|
|
153
|
+
provenance=Provenance.from_distribution(distribution, cls.LICENSE),
|
|
132
154
|
)
|
|
133
155
|
|
|
134
156
|
@classmethod
|
|
@@ -27,6 +27,8 @@ from .core.parse import ColumnType
|
|
|
27
27
|
from .reader import BaseGovDataReader
|
|
28
28
|
|
|
29
29
|
UBA_AIR_BASE = "https://luftdaten.umweltbundesamt.de/api/air-data/v4"
|
|
30
|
+
# No SPDX id exists for the UBA data terms (section 12a EGovG, attribution required), hence a LicenseRef- id.
|
|
31
|
+
UBA_LICENSE = "LicenseRef-UBA-EGovG-12a"
|
|
30
32
|
|
|
31
33
|
OPTION_UBA_STATION = "govdata_uba_station"
|
|
32
34
|
OPTION_UBA_COMPONENT = "govdata_uba_component"
|
|
@@ -56,6 +58,10 @@ def _is_iso_date(value: Any) -> bool:
|
|
|
56
58
|
return True
|
|
57
59
|
|
|
58
60
|
|
|
61
|
+
def _is_non_empty_str(value: Any) -> bool:
|
|
62
|
+
return isinstance(value, str) and bool(value)
|
|
63
|
+
|
|
64
|
+
|
|
59
65
|
# Canonical, stable output schema. The v4 measures leaf array is fixed by the API contract as
|
|
60
66
|
# [component id, scope id, value, date end, index]; the outer keys prepend the station id and the
|
|
61
67
|
# measurement start datetime. Names are canonical (not read from the response) so feature selection
|
|
@@ -239,31 +245,50 @@ class UbaAirReader(BaseGovDataReader[GovDataLocator]):
|
|
|
239
245
|
CSV readers.
|
|
240
246
|
"""
|
|
241
247
|
|
|
248
|
+
LICENSE: ClassVar[str | None] = UBA_LICENSE
|
|
242
249
|
READER_OPTIONS: ClassVar[dict[str, PropertySpec]] = {
|
|
243
|
-
OPTION_UBA_STATION: PropertySpec(
|
|
250
|
+
OPTION_UBA_STATION: PropertySpec(
|
|
251
|
+
"UBA station id.", strict_validation=True, element_validator=is_positive_int, scalar_only=True
|
|
252
|
+
),
|
|
244
253
|
OPTION_UBA_COMPONENT: PropertySpec(
|
|
245
254
|
"UBA component id (see the UBA components endpoint).",
|
|
246
255
|
strict_validation=True,
|
|
247
256
|
element_validator=is_positive_int,
|
|
257
|
+
scalar_only=True,
|
|
248
258
|
),
|
|
249
259
|
OPTION_UBA_SCOPE: PropertySpec(
|
|
250
260
|
"UBA scope id (see the UBA scopes endpoint).",
|
|
251
261
|
strict_validation=True,
|
|
252
262
|
element_validator=is_positive_int,
|
|
263
|
+
scalar_only=True,
|
|
253
264
|
),
|
|
254
265
|
OPTION_UBA_DATE_FROM: PropertySpec(
|
|
255
|
-
"Query window start, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date
|
|
266
|
+
"Query window start, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date, scalar_only=True
|
|
256
267
|
),
|
|
257
268
|
OPTION_UBA_DATE_TO: PropertySpec(
|
|
258
|
-
"Query window end, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date
|
|
269
|
+
"Query window end, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date, scalar_only=True
|
|
259
270
|
),
|
|
260
271
|
OPTION_UBA_TIME_FROM: PropertySpec(
|
|
261
|
-
"Start hour slot (1-24).",
|
|
272
|
+
"Start hour slot (1-24).",
|
|
273
|
+
default=1,
|
|
274
|
+
strict_validation=True,
|
|
275
|
+
element_validator=_is_hour_slot,
|
|
276
|
+
scalar_only=True,
|
|
262
277
|
),
|
|
263
278
|
OPTION_UBA_TIME_TO: PropertySpec(
|
|
264
|
-
"End hour slot (1-24).",
|
|
279
|
+
"End hour slot (1-24).",
|
|
280
|
+
default=24,
|
|
281
|
+
strict_validation=True,
|
|
282
|
+
element_validator=_is_hour_slot,
|
|
283
|
+
scalar_only=True,
|
|
284
|
+
),
|
|
285
|
+
OPTION_UBA_LANG: PropertySpec(
|
|
286
|
+
"UBA API response language.",
|
|
287
|
+
default="en",
|
|
288
|
+
strict_validation=True,
|
|
289
|
+
element_validator=_is_non_empty_str,
|
|
290
|
+
scalar_only=True,
|
|
265
291
|
),
|
|
266
|
-
OPTION_UBA_LANG: PropertySpec("UBA API response language.", default="en"),
|
|
267
292
|
}
|
|
268
293
|
|
|
269
294
|
@classmethod
|
|
@@ -274,23 +299,23 @@ class UbaAirReader(BaseGovDataReader[GovDataLocator]):
|
|
|
274
299
|
def match_subclass_data_access(cls, data_access: Any, feature_names: list[str], options: Any) -> Any:
|
|
275
300
|
if data_access is not True:
|
|
276
301
|
return None
|
|
277
|
-
date_from = cls.
|
|
278
|
-
date_to = cls.
|
|
302
|
+
date_from = cls.reader_option(OPTION_UBA_DATE_FROM, options)
|
|
303
|
+
date_to = cls.reader_option(OPTION_UBA_DATE_TO, options)
|
|
279
304
|
if date_from > date_to:
|
|
280
305
|
raise ValueError(f"{cls.__name__}: date_from {date_from!r} is after date_to {date_to!r}.")
|
|
281
|
-
time_from = cls.
|
|
282
|
-
time_to = cls.
|
|
306
|
+
time_from = cls.reader_option(OPTION_UBA_TIME_FROM, options)
|
|
307
|
+
time_to = cls.reader_option(OPTION_UBA_TIME_TO, options)
|
|
283
308
|
if int(time_from) > int(time_to):
|
|
284
309
|
raise ValueError(f"{cls.__name__}: time_from {time_from!r} is after time_to {time_to!r}.")
|
|
285
310
|
url = uba_measures_url(
|
|
286
|
-
station=cls.
|
|
287
|
-
component=cls.
|
|
288
|
-
scope=cls.
|
|
311
|
+
station=cls.reader_option(OPTION_UBA_STATION, options),
|
|
312
|
+
component=cls.reader_option(OPTION_UBA_COMPONENT, options),
|
|
313
|
+
scope=cls.reader_option(OPTION_UBA_SCOPE, options),
|
|
289
314
|
date_from=date_from,
|
|
290
315
|
date_to=date_to,
|
|
291
316
|
time_from=time_from,
|
|
292
317
|
time_to=time_to,
|
|
293
|
-
lang=cls.
|
|
318
|
+
lang=cls.reader_option(OPTION_UBA_LANG, options),
|
|
294
319
|
)
|
|
295
320
|
return GovDataLocator(distribution_url=url)
|
|
296
321
|
|