Skip to content

Commit 34cd4d6

Browse files
authored
Merge pull request #337 from lincc-frameworks/nest_lists_fix
fix nest_lists for non-unique index
2 parents 919fe82 + ad7a825 commit 34cd4d6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/nested_pandas/nestedframe/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,9 @@ def from_lists(cls, df, base_columns=None, list_columns=None, name="nested"):
594594
packed_df = pack_lists(df[list_columns])
595595
packed_df.name = name
596596

597-
# join the nested column to the base_column df
597+
# concat the nested column to the base_column df
598598
if base_columns is not None:
599-
return df[base_columns].join(packed_df)
599+
return pd.concat([df[base_columns], packed_df], axis=1)
600600
# or just return the packed_df as a nestedframe if no base cols
601601
else:
602602
return NestedFrame(packed_df.to_frame())

tests/nested_pandas/nestedframe/test_nestedframe.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,17 @@ def test_nest_lists():
20322032
res = ndf.nest_lists("nested", ["c", "b"])
20332033

20342034

2035+
def test_nestlists_nonunique_index():
2036+
"""Test that nest_lists works with a non-unique index."""
2037+
nf = generate_data(5, 10)
2038+
nf_lists = nf["a", "b"].join(nf["nested"].nest.to_lists())
2039+
nf_lists.index = [0, 0, 1, 1, 2]
2040+
nf_repacked = nf_lists.nest_lists(["t", "flux", "band"], "nested")
2041+
2042+
nf.index = [0, 0, 1, 1, 2]
2043+
assert nf_repacked.equals(nf)
2044+
2045+
20352046
def test_delitem_base_and_nested():
20362047
"""Test that __delitem__ works for both base and nested columns."""
20372048
base = NestedFrame(data={"a": [1, 2, 3], "b": [2, 4, 6]}, index=[0, 1, 2])

0 commit comments

Comments
 (0)