diff --git a/qlib/contrib/data/utils/sepdf.py b/qlib/contrib/data/utils/sepdf.py index a6a56713e..00e14e147 100644 --- a/qlib/contrib/data/utils/sepdf.py +++ b/qlib/contrib/data/utils/sepdf.py @@ -24,6 +24,10 @@ class SepDataFrame: SepDataFrame tries to act like a DataFrame whose column with multiindex """ + # TODO: + # SepDataFrame try to behave like pandas dataframe, but it is still not them same + # Contributions are welcome to make it more complete. + def __init__(self, df_dict: Dict[str, pd.DataFrame], join: str, skip_align=False): """ initialize the data based on the dataframe dictionary @@ -77,7 +81,11 @@ class SepDataFrame: def _update_join(self): if self.join not in self: - self.join = next(iter(self._df_dict.keys())) + if len(self._df_dict) > 0: + self.join = next(iter(self._df_dict.keys())) + else: + # NOTE: this will change the behavior of previous reindex when all the keys are empty + self.join = None def __getitem__(self, item): # TODO: behave more like pandas when multiindex diff --git a/tests/misc/test_sepdf.py b/tests/misc/test_sepdf.py index 6597ddaab..b8daa35f5 100644 --- a/tests/misc/test_sepdf.py +++ b/tests/misc/test_sepdf.py @@ -47,8 +47,13 @@ class SepDF(unittest.TestCase): two -0.600639 -0.291694} """ self.assertEqual(self.to_str(sdf._df_dict), self.to_str(exp)) - # self.assertEqual(self.to_str(data.tail()), self.to_str(res)) + del df["g1"] + del df["g2"] + # it will not raise error, and df will be an empty dataframe + + del sdf["g1"] + del sdf["g2"] # sdf should support deleting all the columns if __name__ == "__main__": unittest.main()