mloda-plugin-govdata 0.2.3__tar.gz → 0.2.4__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.2.3 → mloda_plugin_govdata-0.2.4}/PKG-INFO +22 -8
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/README.md +20 -6
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/__init__.py +23 -1
- mloda_plugin_govdata-0.2.4/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py +94 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/reader.py +10 -5
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_reader.py +37 -2
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_uba.py +114 -6
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/uba.py +87 -5
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/PKG-INFO +22 -8
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/requires.txt +1 -1
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/pyproject.toml +2 -2
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/tests/test_mloda_imports.py +11 -0
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py +0 -48
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/LICENSE +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/cache.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/client.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/discovery.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/locator.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/core/parse.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/feature.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/population.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/conftest.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_cache.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_client.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_discovery.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_parse.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata/feature_groups/govdata/tests/test_parse_hypothesis.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/SOURCES.txt +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/dependency_links.txt +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/top_level.txt +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/setup.cfg +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/tests/test_demo_definition.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mloda-plugin-govdata
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: mloda plugin providing connectors and harmonization for German government data (GovData.de CKAN API, Destatis GENESIS API v3).
|
|
5
5
|
Author-email: Tom Kaltofen <tomkaltofen@mloda.ai>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -12,7 +12,7 @@ Project-URL: Prototype Fund, https://www.prototypefund.de/projects/mloda-plugin-
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
-
Requires-Dist: mloda<0.
|
|
15
|
+
Requires-Dist: mloda<0.12.0,>=0.11.0
|
|
16
16
|
Requires-Dist: mloda-testing>=0.3.1
|
|
17
17
|
Requires-Dist: httpx>=0.27
|
|
18
18
|
Requires-Dist: pandas>=2.0
|
|
@@ -90,7 +90,7 @@ Got a slug but not the column names? `peek` lists what you can request as featur
|
|
|
90
90
|
StuttgartPopulationReader.peek(slug) # {"Stichtag": "date32[day]", "Stadtbezirk": "string", ...}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(
|
|
93
|
+
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(uba_measures_url(...))`) and downloads through the cache, so the actual feature request reuses the file. `peek` takes a raw URL, bypassing the `READER_OPTIONS` validation below. A typo in a feature name fails with the available columns and a close-match suggestion instead of a raw KeyError.
|
|
94
94
|
|
|
95
95
|
The elections reader handles a direct CSV URL whose file has a multi-row merged header (Bundeswahlleiterin `kerg.csv`):
|
|
96
96
|
|
|
@@ -104,16 +104,30 @@ result = mloda.run_all(
|
|
|
104
104
|
)
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp.
|
|
107
|
+
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp. Query parameters are per-feature options, not a pre-built URL (here: hourly ozone at station 143); a bad value is rejected during feature resolution, before any network call:
|
|
108
108
|
|
|
109
109
|
```python
|
|
110
|
-
from mloda_plugin_govdata.feature_groups.govdata import
|
|
110
|
+
from mloda_plugin_govdata.feature_groups.govdata import (
|
|
111
|
+
OPTION_UBA_COMPONENT,
|
|
112
|
+
OPTION_UBA_DATE_FROM,
|
|
113
|
+
OPTION_UBA_DATE_TO,
|
|
114
|
+
OPTION_UBA_SCOPE,
|
|
115
|
+
OPTION_UBA_STATION,
|
|
116
|
+
UbaAirReader,
|
|
117
|
+
)
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
uba_options = {
|
|
120
|
+
UbaAirReader: True,
|
|
121
|
+
OPTION_UBA_STATION: 143,
|
|
122
|
+
OPTION_UBA_COMPONENT: 3,
|
|
123
|
+
OPTION_UBA_SCOPE: 2,
|
|
124
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
125
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
126
|
+
}
|
|
113
127
|
result = mloda.run_all(
|
|
114
128
|
[
|
|
115
|
-
Feature("date_start", options=
|
|
116
|
-
Feature("value", options=
|
|
129
|
+
Feature("date_start", options=uba_options),
|
|
130
|
+
Feature("value", options=uba_options),
|
|
117
131
|
],
|
|
118
132
|
compute_frameworks=["PyArrowTable"],
|
|
119
133
|
)
|
|
@@ -54,7 +54,7 @@ Got a slug but not the column names? `peek` lists what you can request as featur
|
|
|
54
54
|
StuttgartPopulationReader.peek(slug) # {"Stichtag": "date32[day]", "Stadtbezirk": "string", ...}
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(
|
|
57
|
+
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(uba_measures_url(...))`) and downloads through the cache, so the actual feature request reuses the file. `peek` takes a raw URL, bypassing the `READER_OPTIONS` validation below. A typo in a feature name fails with the available columns and a close-match suggestion instead of a raw KeyError.
|
|
58
58
|
|
|
59
59
|
The elections reader handles a direct CSV URL whose file has a multi-row merged header (Bundeswahlleiterin `kerg.csv`):
|
|
60
60
|
|
|
@@ -68,16 +68,30 @@ result = mloda.run_all(
|
|
|
68
68
|
)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp.
|
|
71
|
+
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp. Query parameters are per-feature options, not a pre-built URL (here: hourly ozone at station 143); a bad value is rejected during feature resolution, before any network call:
|
|
72
72
|
|
|
73
73
|
```python
|
|
74
|
-
from mloda_plugin_govdata.feature_groups.govdata import
|
|
74
|
+
from mloda_plugin_govdata.feature_groups.govdata import (
|
|
75
|
+
OPTION_UBA_COMPONENT,
|
|
76
|
+
OPTION_UBA_DATE_FROM,
|
|
77
|
+
OPTION_UBA_DATE_TO,
|
|
78
|
+
OPTION_UBA_SCOPE,
|
|
79
|
+
OPTION_UBA_STATION,
|
|
80
|
+
UbaAirReader,
|
|
81
|
+
)
|
|
75
82
|
|
|
76
|
-
|
|
83
|
+
uba_options = {
|
|
84
|
+
UbaAirReader: True,
|
|
85
|
+
OPTION_UBA_STATION: 143,
|
|
86
|
+
OPTION_UBA_COMPONENT: 3,
|
|
87
|
+
OPTION_UBA_SCOPE: 2,
|
|
88
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
89
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
90
|
+
}
|
|
77
91
|
result = mloda.run_all(
|
|
78
92
|
[
|
|
79
|
-
Feature("date_start", options=
|
|
80
|
-
Feature("value", options=
|
|
93
|
+
Feature("date_start", options=uba_options),
|
|
94
|
+
Feature("value", options=uba_options),
|
|
81
95
|
],
|
|
82
96
|
compute_frameworks=["PyArrowTable"],
|
|
83
97
|
)
|
|
@@ -21,9 +21,31 @@ from .core.parse import ColumnType, parse_german_csv, parse_german_csv_bytes, pa
|
|
|
21
21
|
from .feature import GovDataFeature
|
|
22
22
|
from .population import POPULATION_SCHEMA, POPULATION_SLUG, StuttgartPopulationReader
|
|
23
23
|
from .reader import BaseGovDataReader, GovDataReader
|
|
24
|
-
from .uba import
|
|
24
|
+
from .uba import (
|
|
25
|
+
OPTION_UBA_COMPONENT,
|
|
26
|
+
OPTION_UBA_DATE_FROM,
|
|
27
|
+
OPTION_UBA_DATE_TO,
|
|
28
|
+
OPTION_UBA_LANG,
|
|
29
|
+
OPTION_UBA_SCOPE,
|
|
30
|
+
OPTION_UBA_STATION,
|
|
31
|
+
OPTION_UBA_TIME_FROM,
|
|
32
|
+
OPTION_UBA_TIME_TO,
|
|
33
|
+
UBA_AIR_BASE,
|
|
34
|
+
UbaAirReader,
|
|
35
|
+
parse_uba_measures,
|
|
36
|
+
parse_uba_measures_bytes,
|
|
37
|
+
uba_measures_url,
|
|
38
|
+
)
|
|
25
39
|
|
|
26
40
|
__all__ = [
|
|
41
|
+
"OPTION_UBA_COMPONENT",
|
|
42
|
+
"OPTION_UBA_DATE_FROM",
|
|
43
|
+
"OPTION_UBA_DATE_TO",
|
|
44
|
+
"OPTION_UBA_LANG",
|
|
45
|
+
"OPTION_UBA_SCOPE",
|
|
46
|
+
"OPTION_UBA_STATION",
|
|
47
|
+
"OPTION_UBA_TIME_FROM",
|
|
48
|
+
"OPTION_UBA_TIME_TO",
|
|
27
49
|
"OPTION_WAHL_HEADER_ROWS",
|
|
28
50
|
"OPTION_WAHL_LABEL_COLUMNS",
|
|
29
51
|
"OPTION_WAHL_SKIPROWS",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Bundeswahlleiterin federal election results (M1 elections theme, kerg.csv)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import numbers
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, ClassVar
|
|
8
|
+
|
|
9
|
+
import pyarrow as pa
|
|
10
|
+
from mloda.provider import PropertySpec, is_positive_int
|
|
11
|
+
from mloda.user import Options
|
|
12
|
+
|
|
13
|
+
from .core.discovery import ResolvedDistribution
|
|
14
|
+
from .core.locator import GovDataLocator
|
|
15
|
+
from .core.parse import ColumnType, parse_multi_header_csv
|
|
16
|
+
from .reader import BaseGovDataReader
|
|
17
|
+
|
|
18
|
+
# Feature-option keys steering the multi-header election parse; defaults are the btw25 kerg.csv
|
|
19
|
+
# geometry, so a new election file is a per-feature configuration change, not a code change.
|
|
20
|
+
OPTION_WAHL_SKIPROWS = "govdata_wahl_skiprows"
|
|
21
|
+
OPTION_WAHL_HEADER_ROWS = "govdata_wahl_header_rows"
|
|
22
|
+
OPTION_WAHL_LABEL_COLUMNS = "govdata_wahl_label_columns"
|
|
23
|
+
OPTION_WAHL_VALUE_TYPE = "govdata_wahl_value_type"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _is_non_negative_int(value: Any) -> bool:
|
|
27
|
+
"""Element validator for a count that may legitimately be zero (the degenerate geometry:
|
|
28
|
+
a single-header export needs ``skiprows=0`` or ``label_columns=0``). Mirrors mloda's
|
|
29
|
+
``is_positive_int`` (rejects bool, accepts numpy integers and decimal strings) but admits 0.
|
|
30
|
+
"""
|
|
31
|
+
if isinstance(value, bool):
|
|
32
|
+
return False
|
|
33
|
+
if isinstance(value, numbers.Integral):
|
|
34
|
+
return int(value) >= 0
|
|
35
|
+
return isinstance(value, str) and value.isdecimal() and int(value) >= 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BundeswahlleiterinReader(BaseGovDataReader):
|
|
39
|
+
"""Reads German election-result CSVs with the Bundeswahlleiterin kerg.csv as the default geometry.
|
|
40
|
+
|
|
41
|
+
The header geometry defaults to the btw25 kerg.csv layout (5-line preamble, 3-row merged
|
|
42
|
+
header, 4 label columns, integer values) and is overridable per feature via the
|
|
43
|
+
``OPTION_WAHL_*`` option keys. A degenerate geometry (``header_rows=1``, ``skiprows=0``)
|
|
44
|
+
covers single-header publisher exports, so connecting the next election is a
|
|
45
|
+
configuration step instead of a code change.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
READER_OPTIONS: ClassVar[dict[str, PropertySpec]] = {
|
|
49
|
+
OPTION_WAHL_SKIPROWS: PropertySpec(
|
|
50
|
+
"Preamble lines to skip before the header block.",
|
|
51
|
+
default=5,
|
|
52
|
+
strict_validation=True,
|
|
53
|
+
element_validator=_is_non_negative_int,
|
|
54
|
+
),
|
|
55
|
+
OPTION_WAHL_HEADER_ROWS: PropertySpec(
|
|
56
|
+
"Merged header rows flattened into column names.",
|
|
57
|
+
default=3,
|
|
58
|
+
strict_validation=True,
|
|
59
|
+
element_validator=is_positive_int,
|
|
60
|
+
),
|
|
61
|
+
OPTION_WAHL_LABEL_COLUMNS: PropertySpec(
|
|
62
|
+
"Leading columns typed as strings, not value_type.",
|
|
63
|
+
default=4,
|
|
64
|
+
strict_validation=True,
|
|
65
|
+
element_validator=_is_non_negative_int,
|
|
66
|
+
),
|
|
67
|
+
OPTION_WAHL_VALUE_TYPE: PropertySpec(
|
|
68
|
+
"ColumnType of the non-label columns.",
|
|
69
|
+
default=ColumnType.INTEGER,
|
|
70
|
+
strict_validation=True,
|
|
71
|
+
allowed_values=tuple(ColumnType),
|
|
72
|
+
),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def match_subclass_data_access(cls, data_access: Any, feature_names: list[str], options: Any) -> Any:
|
|
77
|
+
locator = super().match_subclass_data_access(data_access, feature_names, options)
|
|
78
|
+
if locator is None:
|
|
79
|
+
return None
|
|
80
|
+
for key in cls.READER_OPTIONS:
|
|
81
|
+
cls._scalar_reader_option(key, options)
|
|
82
|
+
return locator
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def _parse(
|
|
86
|
+
cls, path: Path, locator: GovDataLocator, distribution: ResolvedDistribution, options: Options | None = None
|
|
87
|
+
) -> pa.Table:
|
|
88
|
+
return parse_multi_header_csv(
|
|
89
|
+
path,
|
|
90
|
+
skiprows=int(cls.reader_option(OPTION_WAHL_SKIPROWS, options)), # non-numeric values raise loudly
|
|
91
|
+
header_rows=int(cls.reader_option(OPTION_WAHL_HEADER_ROWS, options)),
|
|
92
|
+
label_columns=int(cls.reader_option(OPTION_WAHL_LABEL_COLUMNS, options)),
|
|
93
|
+
value_type=ColumnType(cls.reader_option(OPTION_WAHL_VALUE_TYPE, options)),
|
|
94
|
+
)
|
|
@@ -16,11 +16,8 @@ from typing import Any, ClassVar
|
|
|
16
16
|
|
|
17
17
|
import pyarrow as pa
|
|
18
18
|
from mloda.provider import FeatureSet
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# returns a pyarrow Table. Public path since mloda 0.10.0 (lazy export); resolving it imports and
|
|
22
|
-
# registers the framework class.
|
|
23
|
-
from mloda.user import Options, PyArrowTable # noqa: F401
|
|
19
|
+
from mloda.user import Options
|
|
20
|
+
from mloda.user.pyarrow import PyArrowTable # noqa: F401
|
|
24
21
|
from mloda_plugins.feature_group.input_data.read_file import ReadFile
|
|
25
22
|
|
|
26
23
|
from .core.cache import DownloadCache
|
|
@@ -85,6 +82,14 @@ class BaseGovDataReader(ReadFile):
|
|
|
85
82
|
table = cls._read_table(cls._coerce_locator(data_access))
|
|
86
83
|
return {field.name: str(field.type) for field in table.schema}
|
|
87
84
|
|
|
85
|
+
@classmethod
|
|
86
|
+
def _scalar_reader_option(cls, key: str, options: Any) -> Any:
|
|
87
|
+
"""Reject a collection value, since strict_validation only checks list elements individually."""
|
|
88
|
+
value = cls.reader_option(key, options)
|
|
89
|
+
if isinstance(value, (list, tuple, set, frozenset)):
|
|
90
|
+
raise ValueError(f"{cls.__name__} option '{key}' takes a single value, got {value!r}.") # noqa: TRY004
|
|
91
|
+
return value
|
|
92
|
+
|
|
88
93
|
@classmethod
|
|
89
94
|
def _coerce_locator(cls, data_access: Any) -> GovDataLocator:
|
|
90
95
|
locator = GovDataLocator.coerce(data_access)
|
|
@@ -66,8 +66,6 @@ def test_feature_group_uses_base_govdata_reader() -> None:
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
def test_class_options_key_normalizes_to_reader_name() -> None:
|
|
69
|
-
# The reader class works as an options key; it normalizes to the class-name string (mloda >=0.10.0).
|
|
70
|
-
# The cast bridges a 0.10.0 typing gap: the runtime accepts class keys, the hints only admit str.
|
|
71
69
|
options = Options(cast(dict[str, Any], {GovDataReader: SLUG}))
|
|
72
70
|
assert options.get(GovDataReader.__name__) == SLUG
|
|
73
71
|
|
|
@@ -218,6 +216,43 @@ def test_bad_geometry_option_raises(fixtures_dir: Path) -> None:
|
|
|
218
216
|
BundeswahlleiterinReader._parse(fixtures_dir / "kerg_sample.csv", locator, distribution, options)
|
|
219
217
|
|
|
220
218
|
|
|
219
|
+
@pytest.mark.parametrize(
|
|
220
|
+
("bad_option", "bad_value"),
|
|
221
|
+
[
|
|
222
|
+
(OPTION_WAHL_SKIPROWS, -1),
|
|
223
|
+
(OPTION_WAHL_HEADER_ROWS, 0),
|
|
224
|
+
(OPTION_WAHL_LABEL_COLUMNS, -1),
|
|
225
|
+
(OPTION_WAHL_VALUE_TYPE, "not-a-column-type"),
|
|
226
|
+
],
|
|
227
|
+
)
|
|
228
|
+
@respx.mock
|
|
229
|
+
def test_invalid_geometry_option_rejected_before_any_network_call(bad_option: str, bad_value: Any) -> None:
|
|
230
|
+
with pytest.raises(ValueError, match=f"reader option '{bad_option}' value .* is rejected"):
|
|
231
|
+
mloda.run_all(
|
|
232
|
+
[Feature("Gebiet", options={BundeswahlleiterinReader.__name__: KERG_URL, bad_option: bad_value})],
|
|
233
|
+
compute_frameworks=["PyArrowTable"],
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@pytest.mark.parametrize(
|
|
238
|
+
("collection_option", "collection_value"),
|
|
239
|
+
[
|
|
240
|
+
(OPTION_WAHL_SKIPROWS, [5, 6]),
|
|
241
|
+
(OPTION_WAHL_HEADER_ROWS, [3, 4]),
|
|
242
|
+
(OPTION_WAHL_LABEL_COLUMNS, [4, 5]),
|
|
243
|
+
(OPTION_WAHL_VALUE_TYPE, ["integer", "float"]),
|
|
244
|
+
],
|
|
245
|
+
)
|
|
246
|
+
@respx.mock
|
|
247
|
+
def test_geometry_collection_value_rejected_before_any_network_call(
|
|
248
|
+
collection_option: str, collection_value: list[Any]
|
|
249
|
+
) -> None:
|
|
250
|
+
# Each element is valid alone, so strict_validation admits the list; the scalar guard catches it first.
|
|
251
|
+
options = {BundeswahlleiterinReader.__name__: KERG_URL, collection_option: collection_value}
|
|
252
|
+
with pytest.raises(ValueError, match="takes a single value"):
|
|
253
|
+
mloda.run_all([Feature("Gebiet", options=options)], compute_frameworks=["PyArrowTable"])
|
|
254
|
+
|
|
255
|
+
|
|
221
256
|
@pytest.mark.live
|
|
222
257
|
def test_berlin_wahl_live_end_to_end() -> None:
|
|
223
258
|
result = mloda.run_all(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tests for the UBA Air Data reader: Level 1 (flatten / URL), Level 2 (recorded), Level 3 (live)."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
from datetime import date
|
|
4
5
|
from pathlib import Path
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
@@ -13,6 +14,14 @@ from hypothesis import strategies as st
|
|
|
13
14
|
from mloda.user import Feature, mloda
|
|
14
15
|
|
|
15
16
|
from mloda_plugin_govdata.feature_groups.govdata.uba import (
|
|
17
|
+
OPTION_UBA_COMPONENT,
|
|
18
|
+
OPTION_UBA_DATE_FROM,
|
|
19
|
+
OPTION_UBA_DATE_TO,
|
|
20
|
+
OPTION_UBA_LANG,
|
|
21
|
+
OPTION_UBA_SCOPE,
|
|
22
|
+
OPTION_UBA_STATION,
|
|
23
|
+
OPTION_UBA_TIME_FROM,
|
|
24
|
+
OPTION_UBA_TIME_TO,
|
|
16
25
|
UBA_AIR_BASE,
|
|
17
26
|
UbaAirReader,
|
|
18
27
|
parse_uba_measures_bytes,
|
|
@@ -27,6 +36,17 @@ def _demo_url() -> str:
|
|
|
27
36
|
return uba_measures_url(station=143, component=3, scope=2, date_from="2025-01-01", date_to="2025-01-01")
|
|
28
37
|
|
|
29
38
|
|
|
39
|
+
def _demo_options() -> dict[str, Any]:
|
|
40
|
+
return {
|
|
41
|
+
UbaAirReader.__name__: True,
|
|
42
|
+
OPTION_UBA_STATION: 143,
|
|
43
|
+
OPTION_UBA_COMPONENT: 3,
|
|
44
|
+
OPTION_UBA_SCOPE: 2,
|
|
45
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
46
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
30
50
|
# --- Level 1: URL builder ---------------------------------------------------------------
|
|
31
51
|
|
|
32
52
|
|
|
@@ -161,13 +181,12 @@ def test_flatten_row_count_matches_leaves(stations: dict[str, dict[str, list[Any
|
|
|
161
181
|
def test_uba_reader_level2(fixtures_dir: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
162
182
|
monkeypatch.setattr(UbaAirReader, "cache_dir", str(tmp_path))
|
|
163
183
|
measures_bytes = (fixtures_dir / "uba_measures.json").read_bytes()
|
|
164
|
-
|
|
165
|
-
respx.get(url).mock(return_value=httpx.Response(200, content=measures_bytes))
|
|
184
|
+
respx.get(_demo_url()).mock(return_value=httpx.Response(200, content=measures_bytes))
|
|
166
185
|
|
|
167
186
|
result = mloda.run_all(
|
|
168
187
|
[
|
|
169
|
-
Feature("value", options=
|
|
170
|
-
Feature("date_start", options=
|
|
188
|
+
Feature("value", options=dict(_demo_options())),
|
|
189
|
+
Feature("date_start", options=dict(_demo_options())),
|
|
171
190
|
],
|
|
172
191
|
compute_frameworks=["PyArrowTable"],
|
|
173
192
|
)
|
|
@@ -178,14 +197,103 @@ def test_uba_reader_level2(fixtures_dir: Path, tmp_path: Path, monkeypatch: pyte
|
|
|
178
197
|
assert table.column("value").to_pylist()[0] == 37.0
|
|
179
198
|
|
|
180
199
|
|
|
200
|
+
@respx.mock
|
|
201
|
+
def test_uba_reader_level2_with_non_default_time_and_lang(
|
|
202
|
+
fixtures_dir: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
203
|
+
) -> None:
|
|
204
|
+
monkeypatch.setattr(UbaAirReader, "cache_dir", str(tmp_path))
|
|
205
|
+
measures_bytes = (fixtures_dir / "uba_measures.json").read_bytes()
|
|
206
|
+
url = uba_measures_url(
|
|
207
|
+
station=143, component=3, scope=2, date_from="2025-01-01", date_to="2025-01-01", time_from=6, lang="de"
|
|
208
|
+
)
|
|
209
|
+
respx.get(url).mock(return_value=httpx.Response(200, content=measures_bytes))
|
|
210
|
+
|
|
211
|
+
options = dict(_demo_options())
|
|
212
|
+
options[OPTION_UBA_TIME_FROM] = 6
|
|
213
|
+
options[OPTION_UBA_LANG] = "de"
|
|
214
|
+
result = mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
215
|
+
assert result[0].num_rows == 24
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# --- Level 2: strict validation at resolution time (no network) -------------------------
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@pytest.mark.parametrize(
|
|
222
|
+
("bad_option", "bad_value"),
|
|
223
|
+
[
|
|
224
|
+
(OPTION_UBA_STATION, -1),
|
|
225
|
+
(OPTION_UBA_COMPONENT, 0),
|
|
226
|
+
(OPTION_UBA_SCOPE, "not-a-number"),
|
|
227
|
+
(OPTION_UBA_DATE_FROM, "2025-13-40"),
|
|
228
|
+
(OPTION_UBA_DATE_FROM, "20250101"),
|
|
229
|
+
(OPTION_UBA_DATE_FROM, "2025-W01-1"),
|
|
230
|
+
(OPTION_UBA_DATE_TO, "not-a-date"),
|
|
231
|
+
(OPTION_UBA_DATE_TO, date(2025, 1, 1)),
|
|
232
|
+
(OPTION_UBA_TIME_FROM, 0),
|
|
233
|
+
(OPTION_UBA_TIME_TO, 25),
|
|
234
|
+
],
|
|
235
|
+
)
|
|
236
|
+
@respx.mock
|
|
237
|
+
def test_invalid_uba_option_rejected_before_any_network_call(bad_option: str, bad_value: Any) -> None:
|
|
238
|
+
options = dict(_demo_options())
|
|
239
|
+
options[bad_option] = bad_value
|
|
240
|
+
with pytest.raises(ValueError, match=f"reader option '{bad_option}' value .* is rejected"):
|
|
241
|
+
mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@respx.mock
|
|
245
|
+
def test_missing_required_uba_option_rejected_before_any_network_call() -> None:
|
|
246
|
+
options = dict(_demo_options())
|
|
247
|
+
del options[OPTION_UBA_DATE_FROM]
|
|
248
|
+
with pytest.raises(ValueError, match="required reader option 'govdata_uba_date_from' is absent"):
|
|
249
|
+
mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@respx.mock
|
|
253
|
+
def test_station_collection_value_rejected_before_any_network_call() -> None:
|
|
254
|
+
options = dict(_demo_options())
|
|
255
|
+
options[OPTION_UBA_STATION] = [143, 144]
|
|
256
|
+
with pytest.raises(ValueError, match="takes a single value"):
|
|
257
|
+
mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
@respx.mock
|
|
261
|
+
def test_inverted_date_window_rejected_before_any_network_call() -> None:
|
|
262
|
+
options = dict(_demo_options())
|
|
263
|
+
options[OPTION_UBA_DATE_FROM] = "2025-12-31"
|
|
264
|
+
with pytest.raises(ValueError, match="date_from .* is after date_to"):
|
|
265
|
+
mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@respx.mock
|
|
269
|
+
def test_inverted_time_window_rejected_before_any_network_call() -> None:
|
|
270
|
+
options = dict(_demo_options())
|
|
271
|
+
options[OPTION_UBA_TIME_FROM] = 20
|
|
272
|
+
options[OPTION_UBA_TIME_TO] = 5
|
|
273
|
+
with pytest.raises(ValueError, match="time_from .* is after time_to"):
|
|
274
|
+
mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@respx.mock
|
|
278
|
+
def test_explicit_time_boundaries_accepted(fixtures_dir: Path, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
279
|
+
monkeypatch.setattr(UbaAirReader, "cache_dir", str(tmp_path))
|
|
280
|
+
measures_bytes = (fixtures_dir / "uba_measures.json").read_bytes()
|
|
281
|
+
respx.get(_demo_url()).mock(return_value=httpx.Response(200, content=measures_bytes))
|
|
282
|
+
|
|
283
|
+
options = dict(_demo_options())
|
|
284
|
+
options[OPTION_UBA_TIME_FROM] = 1
|
|
285
|
+
options[OPTION_UBA_TIME_TO] = 24
|
|
286
|
+
result = mloda.run_all([Feature("value", options=options)], compute_frameworks=["PyArrowTable"])
|
|
287
|
+
assert result[0].num_rows == 24
|
|
288
|
+
|
|
289
|
+
|
|
181
290
|
# --- Level 3: live (deselected by default) ----------------------------------------------
|
|
182
291
|
|
|
183
292
|
|
|
184
293
|
@pytest.mark.live
|
|
185
294
|
def test_uba_live_end_to_end() -> None:
|
|
186
|
-
url = _demo_url()
|
|
187
295
|
result = mloda.run_all(
|
|
188
|
-
[Feature("value", options=
|
|
296
|
+
[Feature("value", options=dict(_demo_options()))],
|
|
189
297
|
compute_frameworks=["PyArrowTable"],
|
|
190
298
|
)
|
|
191
299
|
table = result[0]
|
|
@@ -11,12 +11,15 @@ position and uses the self-describing ``indices.data`` block only to detect a ch
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
13
|
import json
|
|
14
|
+
import numbers
|
|
14
15
|
import os
|
|
16
|
+
from datetime import date
|
|
15
17
|
from pathlib import Path
|
|
16
|
-
from typing import Any
|
|
18
|
+
from typing import Any, ClassVar
|
|
17
19
|
from urllib.parse import urlencode
|
|
18
20
|
|
|
19
21
|
import pyarrow as pa
|
|
22
|
+
from mloda.provider import PropertySpec, is_positive_int
|
|
20
23
|
from mloda.user import Options
|
|
21
24
|
|
|
22
25
|
from .core.discovery import ResolvedDistribution
|
|
@@ -26,6 +29,34 @@ from .reader import BaseGovDataReader
|
|
|
26
29
|
|
|
27
30
|
UBA_AIR_BASE = "https://luftdaten.umweltbundesamt.de/api/air-data/v4"
|
|
28
31
|
|
|
32
|
+
OPTION_UBA_STATION = "govdata_uba_station"
|
|
33
|
+
OPTION_UBA_COMPONENT = "govdata_uba_component"
|
|
34
|
+
OPTION_UBA_SCOPE = "govdata_uba_scope"
|
|
35
|
+
OPTION_UBA_DATE_FROM = "govdata_uba_date_from"
|
|
36
|
+
OPTION_UBA_DATE_TO = "govdata_uba_date_to"
|
|
37
|
+
OPTION_UBA_TIME_FROM = "govdata_uba_time_from"
|
|
38
|
+
OPTION_UBA_TIME_TO = "govdata_uba_time_to"
|
|
39
|
+
OPTION_UBA_LANG = "govdata_uba_lang"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _is_hour_slot(value: Any) -> bool:
|
|
43
|
+
if isinstance(value, bool):
|
|
44
|
+
return False
|
|
45
|
+
if isinstance(value, numbers.Integral):
|
|
46
|
+
return 1 <= int(value) <= 24
|
|
47
|
+
return isinstance(value, str) and value.isdecimal() and 1 <= int(value) <= 24
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _is_iso_date(value: Any) -> bool:
|
|
51
|
+
if not isinstance(value, str) or len(value) != 10 or value[4] != "-" or value[7] != "-":
|
|
52
|
+
return False
|
|
53
|
+
try:
|
|
54
|
+
date.fromisoformat(value)
|
|
55
|
+
except ValueError:
|
|
56
|
+
return False
|
|
57
|
+
return True
|
|
58
|
+
|
|
59
|
+
|
|
29
60
|
# Canonical, stable output schema. The v4 measures leaf array is fixed by the API contract as
|
|
30
61
|
# [component id, scope id, value, date end, index]; the outer keys prepend the station id and the
|
|
31
62
|
# measurement start datetime. Names are canonical (not read from the response) so feature selection
|
|
@@ -201,18 +232,69 @@ def parse_uba_measures(path: str | os.PathLike[str]) -> pa.Table:
|
|
|
201
232
|
|
|
202
233
|
|
|
203
234
|
class UbaAirReader(BaseGovDataReader):
|
|
204
|
-
"""Reads the UBA Air Data v4 ``measures``
|
|
235
|
+
"""Reads the UBA Air Data v4 ``measures`` endpoint into a typed Arrow table.
|
|
205
236
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
237
|
+
Query parameters are per-feature ``OPTION_UBA_*`` options, not a pre-built URL. The response
|
|
238
|
+
is flattened to one row per station and measurement timestamp. Reuses the client, cache,
|
|
239
|
+
retry, and direct-URL resolution; only the parse seam and locator building differ from the
|
|
209
240
|
CSV readers.
|
|
210
241
|
"""
|
|
211
242
|
|
|
243
|
+
READER_OPTIONS: ClassVar[dict[str, PropertySpec]] = {
|
|
244
|
+
OPTION_UBA_STATION: PropertySpec("UBA station id.", strict_validation=True, element_validator=is_positive_int),
|
|
245
|
+
OPTION_UBA_COMPONENT: PropertySpec(
|
|
246
|
+
"UBA component id (see the UBA components endpoint).",
|
|
247
|
+
strict_validation=True,
|
|
248
|
+
element_validator=is_positive_int,
|
|
249
|
+
),
|
|
250
|
+
OPTION_UBA_SCOPE: PropertySpec(
|
|
251
|
+
"UBA scope id (see the UBA scopes endpoint).",
|
|
252
|
+
strict_validation=True,
|
|
253
|
+
element_validator=is_positive_int,
|
|
254
|
+
),
|
|
255
|
+
OPTION_UBA_DATE_FROM: PropertySpec(
|
|
256
|
+
"Query window start, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date
|
|
257
|
+
),
|
|
258
|
+
OPTION_UBA_DATE_TO: PropertySpec(
|
|
259
|
+
"Query window end, YYYY-MM-DD.", strict_validation=True, element_validator=_is_iso_date
|
|
260
|
+
),
|
|
261
|
+
OPTION_UBA_TIME_FROM: PropertySpec(
|
|
262
|
+
"Start hour slot (1-24).", default=1, strict_validation=True, element_validator=_is_hour_slot
|
|
263
|
+
),
|
|
264
|
+
OPTION_UBA_TIME_TO: PropertySpec(
|
|
265
|
+
"End hour slot (1-24).", default=24, strict_validation=True, element_validator=_is_hour_slot
|
|
266
|
+
),
|
|
267
|
+
OPTION_UBA_LANG: PropertySpec("UBA API response language.", default="en"),
|
|
268
|
+
}
|
|
269
|
+
|
|
212
270
|
@classmethod
|
|
213
271
|
def suffix(cls) -> tuple[str, ...]:
|
|
214
272
|
return (".json",)
|
|
215
273
|
|
|
274
|
+
@classmethod
|
|
275
|
+
def match_subclass_data_access(cls, data_access: Any, feature_names: list[str], options: Any) -> Any:
|
|
276
|
+
if data_access is not True:
|
|
277
|
+
return None
|
|
278
|
+
date_from = cls._scalar_reader_option(OPTION_UBA_DATE_FROM, options)
|
|
279
|
+
date_to = cls._scalar_reader_option(OPTION_UBA_DATE_TO, options)
|
|
280
|
+
if date_from > date_to:
|
|
281
|
+
raise ValueError(f"{cls.__name__}: date_from {date_from!r} is after date_to {date_to!r}.")
|
|
282
|
+
time_from = cls._scalar_reader_option(OPTION_UBA_TIME_FROM, options)
|
|
283
|
+
time_to = cls._scalar_reader_option(OPTION_UBA_TIME_TO, options)
|
|
284
|
+
if int(time_from) > int(time_to):
|
|
285
|
+
raise ValueError(f"{cls.__name__}: time_from {time_from!r} is after time_to {time_to!r}.")
|
|
286
|
+
url = uba_measures_url(
|
|
287
|
+
station=cls._scalar_reader_option(OPTION_UBA_STATION, options),
|
|
288
|
+
component=cls._scalar_reader_option(OPTION_UBA_COMPONENT, options),
|
|
289
|
+
scope=cls._scalar_reader_option(OPTION_UBA_SCOPE, options),
|
|
290
|
+
date_from=date_from,
|
|
291
|
+
date_to=date_to,
|
|
292
|
+
time_from=time_from,
|
|
293
|
+
time_to=time_to,
|
|
294
|
+
lang=cls._scalar_reader_option(OPTION_UBA_LANG, options),
|
|
295
|
+
)
|
|
296
|
+
return GovDataLocator(distribution_url=url)
|
|
297
|
+
|
|
216
298
|
@classmethod
|
|
217
299
|
def _parse(
|
|
218
300
|
cls, path: Path, locator: GovDataLocator, distribution: ResolvedDistribution, options: Options | None = None
|
{mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mloda-plugin-govdata
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: mloda plugin providing connectors and harmonization for German government data (GovData.de CKAN API, Destatis GENESIS API v3).
|
|
5
5
|
Author-email: Tom Kaltofen <tomkaltofen@mloda.ai>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -12,7 +12,7 @@ Project-URL: Prototype Fund, https://www.prototypefund.de/projects/mloda-plugin-
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
-
Requires-Dist: mloda<0.
|
|
15
|
+
Requires-Dist: mloda<0.12.0,>=0.11.0
|
|
16
16
|
Requires-Dist: mloda-testing>=0.3.1
|
|
17
17
|
Requires-Dist: httpx>=0.27
|
|
18
18
|
Requires-Dist: pandas>=2.0
|
|
@@ -90,7 +90,7 @@ Got a slug but not the column names? `peek` lists what you can request as featur
|
|
|
90
90
|
StuttgartPopulationReader.peek(slug) # {"Stichtag": "date32[day]", "Stadtbezirk": "string", ...}
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
-
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(
|
|
93
|
+
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(uba_measures_url(...))`) and downloads through the cache, so the actual feature request reuses the file. `peek` takes a raw URL, bypassing the `READER_OPTIONS` validation below. A typo in a feature name fails with the available columns and a close-match suggestion instead of a raw KeyError.
|
|
94
94
|
|
|
95
95
|
The elections reader handles a direct CSV URL whose file has a multi-row merged header (Bundeswahlleiterin `kerg.csv`):
|
|
96
96
|
|
|
@@ -104,16 +104,30 @@ result = mloda.run_all(
|
|
|
104
104
|
)
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp.
|
|
107
|
+
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp. Query parameters are per-feature options, not a pre-built URL (here: hourly ozone at station 143); a bad value is rejected during feature resolution, before any network call:
|
|
108
108
|
|
|
109
109
|
```python
|
|
110
|
-
from mloda_plugin_govdata.feature_groups.govdata import
|
|
110
|
+
from mloda_plugin_govdata.feature_groups.govdata import (
|
|
111
|
+
OPTION_UBA_COMPONENT,
|
|
112
|
+
OPTION_UBA_DATE_FROM,
|
|
113
|
+
OPTION_UBA_DATE_TO,
|
|
114
|
+
OPTION_UBA_SCOPE,
|
|
115
|
+
OPTION_UBA_STATION,
|
|
116
|
+
UbaAirReader,
|
|
117
|
+
)
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
uba_options = {
|
|
120
|
+
UbaAirReader: True,
|
|
121
|
+
OPTION_UBA_STATION: 143,
|
|
122
|
+
OPTION_UBA_COMPONENT: 3,
|
|
123
|
+
OPTION_UBA_SCOPE: 2,
|
|
124
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
125
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
126
|
+
}
|
|
113
127
|
result = mloda.run_all(
|
|
114
128
|
[
|
|
115
|
-
Feature("date_start", options=
|
|
116
|
-
Feature("value", options=
|
|
129
|
+
Feature("date_start", options=uba_options),
|
|
130
|
+
Feature("value", options=uba_options),
|
|
117
131
|
],
|
|
118
132
|
compute_frameworks=["PyArrowTable"],
|
|
119
133
|
)
|
|
@@ -6,13 +6,13 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
name = "mloda-plugin-govdata"
|
|
7
7
|
# Always start at least at 0.2.0 to make semver work.
|
|
8
8
|
# Initial release for semver needs also a manually pushed minimum tag (likely 0.2.0).
|
|
9
|
-
version = "0.2.
|
|
9
|
+
version = "0.2.4"
|
|
10
10
|
description = "mloda plugin providing connectors and harmonization for German government data (GovData.de CKAN API, Destatis GENESIS API v3)."
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
license = "Apache-2.0"
|
|
13
13
|
authors = [{ name = "Tom Kaltofen", email = "tomkaltofen@mloda.ai" }]
|
|
14
14
|
dependencies = [
|
|
15
|
-
"mloda>=0.
|
|
15
|
+
"mloda>=0.11.0,<0.12.0",
|
|
16
16
|
"mloda-testing>=0.3.1",
|
|
17
17
|
"httpx>=0.27",
|
|
18
18
|
"pandas>=2.0",
|
|
@@ -21,3 +21,14 @@ def test_mloda_testing_imports() -> None:
|
|
|
21
21
|
from mloda.testing.base import FeatureGroupTestBase
|
|
22
22
|
|
|
23
23
|
assert FeatureGroupTestBase is not None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_mloda_user_imports() -> None:
|
|
27
|
+
"""Verify mloda.user and its pyarrow backend module import work."""
|
|
28
|
+
from mloda.user import Feature, Options, mloda
|
|
29
|
+
from mloda.user.pyarrow import PyArrowTable
|
|
30
|
+
|
|
31
|
+
assert Feature is not None
|
|
32
|
+
assert Options is not None
|
|
33
|
+
assert mloda is not None
|
|
34
|
+
assert PyArrowTable is not None
|
mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"""Bundeswahlleiterin federal election results (M1 elections theme, kerg.csv)."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
import pyarrow as pa
|
|
8
|
-
from mloda.user import Options
|
|
9
|
-
|
|
10
|
-
from .core.discovery import ResolvedDistribution
|
|
11
|
-
from .core.locator import GovDataLocator
|
|
12
|
-
from .core.parse import ColumnType, parse_multi_header_csv
|
|
13
|
-
from .reader import BaseGovDataReader
|
|
14
|
-
|
|
15
|
-
# Feature-option keys steering the multi-header election parse; defaults are the btw25 kerg.csv
|
|
16
|
-
# geometry, so a new election file is a per-feature configuration change, not a code change.
|
|
17
|
-
OPTION_WAHL_SKIPROWS = "govdata_wahl_skiprows"
|
|
18
|
-
OPTION_WAHL_HEADER_ROWS = "govdata_wahl_header_rows"
|
|
19
|
-
OPTION_WAHL_LABEL_COLUMNS = "govdata_wahl_label_columns"
|
|
20
|
-
OPTION_WAHL_VALUE_TYPE = "govdata_wahl_value_type"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class BundeswahlleiterinReader(BaseGovDataReader):
|
|
24
|
-
"""Reads German election-result CSVs with the Bundeswahlleiterin kerg.csv as the default geometry.
|
|
25
|
-
|
|
26
|
-
The header geometry defaults to the btw25 kerg.csv layout (5-line preamble, 3-row merged
|
|
27
|
-
header, 4 label columns, integer values) and is overridable per feature via the
|
|
28
|
-
``OPTION_WAHL_*`` option keys. A degenerate geometry (``header_rows=1``, ``skiprows=0``)
|
|
29
|
-
covers single-header publisher exports, so connecting the next election is a
|
|
30
|
-
configuration step instead of a code change.
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
@classmethod
|
|
34
|
-
def _parse(
|
|
35
|
-
cls, path: Path, locator: GovDataLocator, distribution: ResolvedDistribution, options: Options | None = None
|
|
36
|
-
) -> pa.Table:
|
|
37
|
-
def int_option(key: str, default: int) -> int:
|
|
38
|
-
value = options.get(key) if options is not None else None
|
|
39
|
-
return default if value is None else int(value) # non-numeric values raise loudly
|
|
40
|
-
|
|
41
|
-
raw_value_type = options.get(OPTION_WAHL_VALUE_TYPE) if options is not None else None
|
|
42
|
-
return parse_multi_header_csv(
|
|
43
|
-
path,
|
|
44
|
-
skiprows=int_option(OPTION_WAHL_SKIPROWS, 5),
|
|
45
|
-
header_rows=int_option(OPTION_WAHL_HEADER_ROWS, 3),
|
|
46
|
-
label_columns=int_option(OPTION_WAHL_LABEL_COLUMNS, 4),
|
|
47
|
-
value_type=ColumnType(raw_value_type) if raw_value_type is not None else ColumnType.INTEGER,
|
|
48
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.2.4}/mloda_plugin_govdata.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|