Skip to content

Commit cff8d0b

Browse files
committed
representation tests
1 parent fba5cab commit cff8d0b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/nested_pandas/series/test_nestedseries.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,37 @@ def test_nestedseries_list_lengths():
8282
)
8383

8484
assert list(series.list_lengths) == [2, 2]
85+
86+
87+
def test_nestedseries_to_flat():
88+
"""Test to_flat method of NestedSeries."""
89+
series = NestedSeries(
90+
data=[
91+
(np.array([1, 2]), np.array([0, 1])),
92+
(np.array([3, 4]), np.array([0, 1])),
93+
],
94+
index=[0, 1],
95+
dtype=NestedDtype(pa.struct([("a", pa.list_(pa.int64())), ("b", pa.list_(pa.int64()))])),
96+
)
97+
98+
flat_df = series.to_flat()
99+
assert isinstance(flat_df, pd.DataFrame)
100+
assert list(flat_df.columns) == ["a", "b"]
101+
assert flat_df.shape == (4, 2)
102+
103+
104+
def test_nestedseries_to_lists():
105+
"""Test to_lists method of NestedSeries."""
106+
series = NestedSeries(
107+
data=[
108+
(np.array([1, 2]), np.array([0, 1])),
109+
(np.array([3, 4]), np.array([0, 1])),
110+
],
111+
index=[0, 1],
112+
dtype=NestedDtype(pa.struct([("a", pa.list_(pa.int64())), ("b", pa.list_(pa.int64()))])),
113+
)
114+
115+
lists = series.to_lists()
116+
assert len(lists) == 2
117+
assert lists["a"][0] == [1, 2]
118+
assert lists["a"][1] == [3, 4]

0 commit comments

Comments
 (0)