Skip to content

Commit

Permalink
fix cube functionality: it seems like structure of QEI header part wa…
Browse files Browse the repository at this point in the history
…s changed as well as DQA no longer has information about axis so we assume that the order is preserved (#43)
  • Loading branch information
pmayd committed Dec 8, 2023
1 parent f689756 commit 3d8c347
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions nb/cube.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"c = Cube(name=\"22922KJ1141\")"
"c = Cube(name=\"23211BJ001\")"
]
},
{
Expand All @@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"c.get_data() # TODO: currently broken?"
"c.get_data()"
]
},
{
Expand Down Expand Up @@ -98,6 +98,13 @@
"\n",
"pprint(c.metadata)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -116,7 +123,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.6"
},
"vscode": {
"interpreter": {
Expand Down
10 changes: 5 additions & 5 deletions src/pystatis/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def parse_cube(data: str) -> dict:
data_block.append(line_content)

# the last data block has no header after it so we have to do it here
# for cubes with more than one variable in DQI, we have to repeat the last four columns
# for cubes with more than one variable in DQI, we have to repeat the last two columns
if header:
last_four_columns = header[-4:]
header = header[:-4]
last_two_columns = header[-2:]
header = header[:-2]
for var in cube["DQI"]["NAME"]:
header.extend([f"{var}_{col}" for col in last_four_columns])
header.extend([f"{var}_{col}" for col in last_two_columns])

cube[header_type] = pd.DataFrame(data_block, columns=header)

Expand Down Expand Up @@ -119,7 +119,7 @@ def rename_axes(
old_cols.extend(
[col for col in cube["QEI"].columns if col.startswith("FACH-SCHL")]
)
new_cols.extend(cube["DQA"].sort_values("RHF-ACHSE")["NAME"].to_list())
new_cols.extend(cube["DQA"]["NAME"].to_list())

if rename_time_variable:
old_cols.append("ZI-WERT")
Expand Down
Binary file modified tests/rsc/data.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def cube(request, easy_cube, hard_cube):
[
(
"hard_cube",
(19185, 13),
(22393, 9),
"22922KJ114",
"22922",
["KREISE", "GES", "ERW122", "ELGAT2"],
Expand All @@ -61,7 +61,7 @@ def cube(request, easy_cube, hard_cube):
),
(
"easy_cube",
(42403, 10),
(43567, 8),
"12411BJ001",
"12411",
["DINSG", "NAT", "GES", "FAMST8", "ALT013"],
Expand Down

0 comments on commit 3d8c347

Please sign in to comment.