Skip to content

Commit 42eb06e

Browse files
authored
Merge pull request #351 from lincc-frameworks/fix-350
Fix reduce for non-uniq idx
2 parents 4b382d8 + b483330 commit 42eb06e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/nested_pandas/nestedframe/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,8 @@ def reduce(self, func, *args, infer_nesting=True, append_columns=False, **kwargs
18701870
nested_col = pack_lists(rename_df, name=layer)
18711871
results_nf = results_nf[
18721872
[col for col in results_nf.columns if not col.startswith(f"{layer}.")]
1873-
].join(nested_col)
1873+
]
1874+
results_nf[layer] = nested_col
18741875

18751876
if append_columns:
18761877
# Append the results to the original NestedFrame

tests/nested_pandas/nestedframe/test_nestedframe.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,3 +2199,11 @@ def test_issue294():
21992199
# Failed with a ValueError in the original issue
22002200
nf["nested.c"] = nf["c"]
22012201
nf["nested.mag"] = -2.5 * np.log10(nf["nested.flux"])
2202+
2203+
2204+
def test_issue350():
2205+
"""https://github.com/lincc-frameworks/nested-pandas/issues/350"""
2206+
nf = generate_data(3, 2)
2207+
nf = nf.set_index(np.array([100, 100, 101]))
2208+
result = nf.reduce(lambda flux: {"new.flux": flux}, "nested.flux")
2209+
assert len(result) == 3

0 commit comments

Comments
 (0)