diff --git a/merlin/systems/dag/dictarray.py b/merlin/systems/dag/dictarray.py index 1da6989c5..eb18e45a6 100644 --- a/merlin/systems/dag/dictarray.py +++ b/merlin/systems/dag/dictarray.py @@ -18,6 +18,7 @@ import numpy as np +from merlin.core.dispatch import get_lib from merlin.core.protocols import SeriesLike try: @@ -225,6 +226,25 @@ def copy(self): """ return DictArray(self._columns.copy()) + def to_df(self): + """ + Create a DataFrame from the DictArray + """ + df = get_lib().DataFrame() + for col in self.columns: + df[col] = get_lib().Series(self[col]) + return df + + @classmethod + def from_df(cls, df): + """ + Create a DictArray from a DataFrame + """ + array_dict = {} + for col in df.columns: + array_dict[col] = df[col].to_numpy() + return cls(array_dict) + def _array_lib(): """Dispatch to the appropriate library (cupy or numpy) for the current environment"""