Skip to content

Commit 501f73a

Browse files
committed
Construct pd.Index when there is only one index column
1 parent 95c59de commit 501f73a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/extra/components/dld.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,14 @@ def _build_reduced_pd(self, data, index, entry_level=None, mask_func=None):
185185
if entry_level is not None:
186186
index_df[entry_level] = np.flatnonzero(finite_mask) % num_rows
187187

188-
return pd_cls(np.ascontiguousarray(raw[finite_mask]),
189-
pd.MultiIndex.from_frame(index_df))
188+
if len(index_df.columns) > 1:
189+
# Multiple index columns, create a MultiIndex again.
190+
index = pd.MultiIndex.from_frame(index_df)
191+
else:
192+
# If only a single column is left, build a simple index.
193+
index = pd.Index(index_df[next(iter(index_df.columns))])
194+
195+
return pd_cls(np.ascontiguousarray(raw[finite_mask]), index)
190196

191197
@staticmethod
192198
def insert_aligned_columns(df, columns):

0 commit comments

Comments
 (0)