Skip to content

Commit 94621d7

Browse files
authored
Merge pull request #292 from lincc-frameworks/empty-chunks-accessor
Fix a failure for nest["field"] and empty chunks
2 parents e18390e + cc40fb2 commit 94621d7

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/nested_pandas/series/accessor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ def to_flat(self, fields: list[str] | None = None) -> pd.DataFrame:
125125
flat_series = {}
126126
for field, chunks in flat_chunks.items():
127127
dtype = self._series.dtype.field_dtype(field)
128-
if len(chunks) == 0:
129-
chunks = [pa.array([])]
130-
chunked_array = pa.chunked_array(chunks)
128+
chunked_array = pa.chunked_array(chunks, type=self._series.dtype.fields[field])
131129
flat_series[field] = pd.Series(
132130
chunked_array,
133131
index=index,
@@ -433,7 +431,7 @@ def get_flat_series(self, field: str) -> pd.Series:
433431
flat_array = list_array.flatten()
434432
flat_chunks.append(flat_array)
435433

436-
flat_chunked_array = pa.chunked_array(flat_chunks)
434+
flat_chunked_array = pa.chunked_array(flat_chunks, type=self._series.dtype.fields[field])
437435

438436
return pd.Series(
439437
flat_chunked_array,

0 commit comments

Comments
 (0)