diff --git a/qlib/backtest/position.py b/qlib/backtest/position.py index 18b084fb64..e6f46279f3 100644 --- a/qlib/backtest/position.py +++ b/qlib/backtest/position.py @@ -311,7 +311,7 @@ def fill_stock_value(self, start_time: Union[str, pd.Timestamp], freq: str, last freq=freq, disk_cache=True, ).dropna() - price_dict = price_df.groupby(["instrument"]).tail(1).reset_index(level=1, drop=True)["$close"].to_dict() + price_dict = price_df.groupby(["instrument"], group_keys=False).tail(1)["$close"].to_dict() if len(price_dict) < len(stock_list): lack_stock = set(stock_list) - set(price_dict) diff --git a/qlib/contrib/eva/alpha.py b/qlib/contrib/eva/alpha.py index 86d366d205..34b35365fc 100644 --- a/qlib/contrib/eva/alpha.py +++ b/qlib/contrib/eva/alpha.py @@ -47,14 +47,14 @@ def calc_long_short_prec( if dropna: df.dropna(inplace=True) - group = df.groupby(level=date_col) + group = df.groupby(level=date_col, group_keys=False) def N(x): return int(len(x) * quantile) # find the top/low quantile of prediction and treat them as long and short target - long = group.apply(lambda x: x.nlargest(N(x), columns="pred").label).reset_index(level=0, drop=True) - short = group.apply(lambda x: x.nsmallest(N(x), columns="pred").label).reset_index(level=0, drop=True) + long = group.apply(lambda x: x.nlargest(N(x), columns="pred").label) + short = group.apply(lambda x: x.nsmallest(N(x), columns="pred").label) groupll = long.groupby(date_col) l_dom = groupll.apply(lambda x: x > 0) diff --git a/qlib/contrib/report/analysis_position/parse_position.py b/qlib/contrib/report/analysis_position/parse_position.py index 61064d3e6a..2b64a5bf43 100644 --- a/qlib/contrib/report/analysis_position/parse_position.py +++ b/qlib/contrib/report/analysis_position/parse_position.py @@ -132,7 +132,7 @@ def _calculate_day_value(g_df: pd.DataFrame): g_df["excess_return"] = g_df[_label_name] - g_df[_label_name].mean() return g_df - return df.groupby(level="datetime").apply(_calculate_day_value) + return df.groupby(level="datetime", group_keys=False).apply(_calculate_day_value) def get_position_data( diff --git a/qlib/contrib/report/analysis_position/rank_label.py b/qlib/contrib/report/analysis_position/rank_label.py index fb2fcc6d8b..3e94d174c4 100644 --- a/qlib/contrib/report/analysis_position/rank_label.py +++ b/qlib/contrib/report/analysis_position/rank_label.py @@ -31,7 +31,7 @@ def _get_figure_with_position( ) res_dict = dict() - _pos_gp = _position_df.groupby(level=1) + _pos_gp = _position_df.groupby(level=1, group_keys=False) for _item in _pos_gp: _date = _item[0] _day_df = _item[1] diff --git a/qlib/utils/paral.py b/qlib/utils/paral.py index 3b6671ddbe..0e5090126b 100644 --- a/qlib/utils/paral.py +++ b/qlib/utils/paral.py @@ -51,8 +51,8 @@ def datetime_groupby_apply( def _naive_group_apply(df): if isinstance(apply_func, str): - return getattr(df.groupby(axis=axis, level=level), apply_func)() - return df.groupby(axis=axis, level=level).apply(apply_func) + return getattr(df.groupby(axis=axis, level=level, group_keys=False), apply_func)() + return df.groupby(axis=axis, level=level, group_keys=False).apply(apply_func) if n_jobs != 1: dfs = ParallelExt(n_jobs=n_jobs)(