legacy structure (I hope)

This commit is contained in:
Jan Kieseler
2025-10-16 15:11:50 +02:00
parent 589b50522b
commit cc41ed3c65
2 changed files with 52 additions and 8 deletions
+11 -7
View File
@@ -144,19 +144,23 @@ class MiniFrame:
def copy(self) -> "MiniFrame":
return MiniFrame({k: v.copy() for k, v in self._data.items()})
def to_pandas(self):
def to_pandas(self, indiv_cols: bool = True):
import pandas as pd
df = pd.DataFrame()
out = {}
for k, v in self._data.items():
if v.ndim == 1:
df[k] = v
elif v.ndim == 2:
# expand fixed-size vectors into wide columns
out[k] = v # 1D numeric column
elif v.ndim == 2 and indiv_cols:
# expand into wide columns
for i in range(v.shape[1]):
df[f"{k}_{i}"] = v[:, i]
out[f"{k}_{i}"] = v[:, i]
elif v.ndim == 2 and not indiv_cols:
# legacy nested: one Python list per row (object dtype)
# NOTE: v.tolist() -> List[List[...]] which most legacy code expects
out[k] = pd.Series(v.tolist(), dtype=object)
else:
raise ValueError(f"Column '{k}' has ndim={v.ndim}, not supported.")
return df
return pd.DataFrame(out)
# convenience constructor
@staticmethod