Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cube functionality #43

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -121,7 +121,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
Loading