Skip to content

Commit

Permalink
fixed groupbyerror
Browse files Browse the repository at this point in the history
  • Loading branch information
dodu94 committed Feb 11, 2025
1 parent 74be3a9 commit 2f9e596
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/jade/post/manipulate_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def groupby(tally: pd.DataFrame, by: str, action: str) -> pd.DataFrame:

if by == "all":
grouped = tally
error_series = tally["Error"]
error = np.sqrt((tally["Error"] ** 2).sum())
else:
error_df = tally.set_index(by)["Error"]
rows = {}
rows = []
for idx_val in error_df.index.unique():
subset = error_df.loc[idx_val]
error = np.sqrt(np.sum(subset**2))
rows[idx_val] = error
error_series = pd.Series(rows, name="Error")
err = np.sqrt(np.sum(subset**2))
rows.append(err)
error = pd.Series(rows, name="Error")
grouped = tally.groupby(by, sort=False)

if action == "sum":
Expand All @@ -142,7 +142,7 @@ def groupby(tally: pd.DataFrame, by: str, action: str) -> pd.DataFrame:
else:
df.reset_index(inplace=True)

df["Error"] = error_series
df["Error"] = error

return df

Expand Down
5 changes: 5 additions & 0 deletions tests/post/test_manipulate_tally.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def test_groupby():
result = groupby(df.copy(), "Energy", "min")
assert (result["Value"] == [1, 3]).all()

result = groupby(df.copy(), "all", "sum")
assert result["Value"].iloc[0] == 10
assert result["Error"].iloc[0] == math.sqrt(0.1**2 + 0.2**2 + 0.1**2 + 0.1**2)
assert len(result) == 1


def test_delete_cols():
data = {
Expand Down

0 comments on commit 2f9e596

Please sign in to comment.