Skip to content

Commit e224e18

Browse files
committed
Merge index NaN tests into one parametrized test, fix formatting
https://claude.ai/code/session_01F7cbsuGUbfDoW1oDdiGqf5
1 parent de14ebc commit e224e18

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/nested_pandas/series/packer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def pack_seq(
152152
return series
153153

154154

155-
156155
def pack_sorted_df_into_struct(df: pd.DataFrame, name: str | None = None) -> NestedSeries:
157156
"""Make a structure of lists representation of a "flat" dataframe.
158157

tests/nested_pandas/series/test_packer.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,14 @@ def test_calculate_sorted_index_offsets_raises_when_not_sorted():
600600
packer.calculate_sorted_index_offsets(index)
601601

602602

603-
def test_pack_flat_raises_with_nan_in_index():
603+
@pytest.mark.parametrize(
604+
"index",
605+
[
606+
pd.Index([1.0, 1.0, 2.0, 2.0, np.nan]),
607+
pd.MultiIndex.from_arrays(([1, 1, 2, 2, 2], [1.0, 2.0, np.nan, 1.0, 2.0])),
608+
],
609+
)
610+
def test_pack_flat_raises_with_nan_in_index(index):
604611
"""Test pack_flat() raises informative error when index contains NaN values.
605612
606613
This is a regression test for https://github.com/lincc-frameworks/nested-pandas/issues/440
@@ -610,25 +617,7 @@ def test_pack_flat_raises_with_nan_in_index():
610617
"a": [1, 2, 3, 4, 5],
611618
"b": [0, 1, 0, 1, 0],
612619
},
613-
index=[1.0, 1.0, 2.0, 2.0, np.nan],
614-
)
615-
with pytest.raises(ValueError, match="The index contains NaN values"):
616-
packer.pack_flat(df)
617-
618-
619-
def test_pack_flat_raises_with_nan_in_multiindex():
620-
"""Test pack_flat() raises informative error when MultiIndex contains NaN values.
621-
622-
This is a regression test for https://github.com/lincc-frameworks/nested-pandas/issues/440
623-
"""
624-
df = pd.DataFrame(
625-
data={
626-
"a": [1, 2, 3, 4, 5],
627-
"b": [0, 1, 0, 1, 0],
628-
},
629-
index=pd.MultiIndex.from_arrays(
630-
([1, 1, 2, 2, 2], [1.0, 2.0, np.nan, 1.0, 2.0]),
631-
),
620+
index=index,
632621
)
633622
with pytest.raises(ValueError, match="The index contains NaN values"):
634623
packer.pack_flat(df)

0 commit comments

Comments
 (0)