Skip to content

Commit

Permalink
Merge af5951f into d63cee9
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonbb authored Apr 12, 2024
2 parents d63cee9 + af5951f commit 9f36add
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/nested_pandas/series/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ def to_flat(self, fields: list[str] | None = None) -> pd.DataFrame:
index = np.repeat(self._series.index.values, np.diff(list_array.offsets))
flat_series[field] = pd.Series(
list_array.flatten(),
index=index,
index=pd.Series(index, name=self._series.index.name),
name=field,
copy=False,
)

return pd.DataFrame(flat_series)

@property
Expand Down
7 changes: 6 additions & 1 deletion tests/nested_pandas/series/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ def test_to_flat():
],
names=["a", "b"],
)
series = pd.Series(struct_array, dtype=NestedDtype(struct_array.type), index=[0, 1])

series = pd.Series(
struct_array, dtype=NestedDtype(struct_array.type), index=pd.Series([0, 1], name="idx")
)

flat = series.nest.to_flat()

Expand All @@ -106,10 +109,12 @@ def test_to_flat():
copy=False,
),
},
index=pd.Index([0, 0, 0, 1, 1, 1], name="idx"),
)

assert_array_equal(flat.dtypes, desired.dtypes)
assert_array_equal(flat.index, desired.index)
assert flat.index.name == desired.index.name

for column in flat.columns:
assert_array_equal(flat[column], desired[column])
Expand Down

0 comments on commit 9f36add

Please sign in to comment.