Skip to content

Commit d1982ea

Browse files
committed
Test validate_struct_list_type
1 parent e71239a commit d1982ea

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/nested_pandas/series/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def align_struct_list_offsets(array: pa.StructArray) -> pa.StructArray:
119119
)
120120
new_array = pa.StructArray.from_arrays(
121121
arrays=list_arrays,
122-
type=array.type,
122+
fields=array.type.fields,
123123
)
124124
return new_array
125125

@@ -281,7 +281,7 @@ def validate_list_struct_type(t: pa.ListType) -> None:
281281
raise ValueError(f"Expected a StructType as a list value type, got {t.value_type}")
282282

283283

284-
def validate_struct_list_type(t: pa.ListType) -> None:
284+
def validate_struct_list_type(t: pa.StructType) -> None:
285285
"""Raise a ValueError if not a struct-list-type."""
286286
if not pa.types.is_struct(t):
287287
raise ValueError(f"Expected a StructType, got {t}")

tests/nested_pandas/series/test_series_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
transpose_list_struct_type,
1313
transpose_struct_list_array,
1414
transpose_struct_list_type,
15+
validate_struct_list_type,
1516
)
1617

1718

@@ -116,6 +117,26 @@ def test_align_chunked_struct_list_offsets():
116117
assert output_array.equals(input_array)
117118

118119

120+
def test_validate_struct_list_type():
121+
"""Test validate_struct_list_type function."""
122+
with pytest.raises(ValueError):
123+
validate_struct_list_type(pa.float64())
124+
125+
with pytest.raises(ValueError):
126+
validate_struct_list_type(pa.list_(pa.struct({"a": pa.int64()})))
127+
128+
with pytest.raises(ValueError):
129+
validate_struct_list_type(pa.struct({"a": pa.float64()}))
130+
131+
with pytest.raises(ValueError):
132+
validate_struct_list_type(pa.struct({"a": pa.list_(pa.float64()), "b": pa.float64()}))
133+
134+
assert (
135+
validate_struct_list_type(pa.struct({"a": pa.list_(pa.float64()), "b": pa.list_(pa.float64())}))
136+
is None
137+
)
138+
139+
119140
def test_transpose_struct_list_type():
120141
"""Test transpose_struct_list_type function."""
121142
# Raises for wrong types

0 commit comments

Comments
 (0)