Skip to content
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
1 change: 1 addition & 0 deletions src/nested_pandas/nestedframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ def from_lists(cls, df, base_columns=None, list_columns=None, name="nested"):
# if the dataframe is empty, just return an empty nested column
# since there are no iterable values to pack
packed_df = NestedFrame().join_nested(df[list_columns], name=name)
packed_df.index.name = df.index.name
else:
# Check that each column has iterable elements
for col in list_columns:
Expand Down
11 changes: 11 additions & 0 deletions tests/nested_pandas/nestedframe/test_nestedframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,17 @@ def test_nestlists_nonunique_index():
assert nf_repacked.equals(nf)


def test_nestlists_preserve_index_name():
"""Test that nest_lists preserves the index name with empty dataframes."""

# See https://github.com/lincc-frameworks/nested-pandas/issues/409 for context
nf = generate_data(5, 10, seed=1)
nf.index.name = "objectid"
nf = nf.join(nf["nested"].to_lists())
result = nf.head(0).nest_lists(["t", "flux", "band"], name="nested2").reset_index()
assert "objectid" in result.columns


def test_delitem_base_and_nested():
"""Test that __delitem__ works for both base and nested columns."""
base = NestedFrame(data={"a": [1, 2, 3], "b": [2, 4, 6]}, index=[0, 1, 2])
Expand Down