Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ license = { text = "MIT" }
dependencies = [
"pyyaml",
"numpy",
"pandas>=0.24",
# Since version 1.1.0, pandas supports the ffill and bfill methods.
# Since version 2.1.0, pandas has deprecated the method parameter of the fillna method.
# qlib has updated the fillna method in PR 1987 and limited the minimum version of pandas.
"pandas>=1.1",
# I encoutered an Error that the set_uri does not work when downloading artifacts in mlflow 3.1.1;
# But earlier versions of mlflow does not have this problem.
# But when I switch to 2.*.* version, another error occurs, which is even more strange...
Expand Down
4 changes: 2 additions & 2 deletions qlib/backtest/profit_attribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ def brinson_pa(

stock_group_field = stock_df[group_field].unstack().T
# FIXME: some attributes of some suspend stock is NAN.
stock_group_field = stock_group_field.fillna(method="ffill")
stock_group_field = stock_group_field.ffill()
stock_group_field = stock_group_field.loc[start_date:end_date]

stock_group = get_stock_group(stock_group_field, bench_stock_weight, group_method, group_n)

deal_price_df = stock_df["deal_price"].unstack().T
deal_price_df = deal_price_df.fillna(method="ffill")
deal_price_df = deal_price_df.ffill()

# NOTE:
# The return will be slightly different from the of the return in the report.
Expand Down
4 changes: 2 additions & 2 deletions qlib/contrib/ops/high_freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class FFillNan(ElemOperator):

def _load_internal(self, instrument, start_index, end_index, freq):
series = self.feature.load(instrument, start_index, end_index, freq)
return series.fillna(method="ffill")
return series.ffill()


class BFillNan(ElemOperator):
Expand All @@ -154,7 +154,7 @@ class BFillNan(ElemOperator):

def _load_internal(self, instrument, start_index, end_index, freq):
series = self.feature.load(instrument, start_index, end_index, freq)
return series.fillna(method="bfill")
return series.bfill()


class Date(ElemOperator):
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/report/analysis_position/parse_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_position(position: dict = None) -> pd.DataFrame:

position_weight_df = get_stock_weight_df(position)
# If the day does not exist, use the last weight
position_weight_df.fillna(method="ffill", inplace=True)
position_weight_df.ffill(inplace=True)

previous_data = {"date": None, "code_list": []}

Expand Down
1 change: 0 additions & 1 deletion qlib/data/dataset/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def fetch(
col_set: Union[str, List[str]] = DataHandler.CS_ALL,
fetch_orig: bool = True,
) -> pd.DataFrame:

# Following conflicts may occur
# - Does [20200101", "20210101"] mean selecting this slice or these two days?
# To solve this issue
Expand Down
1 change: 0 additions & 1 deletion qlib/utils/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def init_instance_by_config(
# path like 'file:///<path to pickle file>/obj.pkl'
pr = urlparse(config)
if pr.scheme == "file":

# To enable relative path like file://data/a/b/c.pkl. pr.netloc will be data
path = pr.path
if pr.netloc != "":
Expand Down
2 changes: 1 addition & 1 deletion qlib/utils/resam.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_valid_value(series, last=True):
Nan | float
the first/last valid value
"""
return series.fillna(method="ffill").iloc[-1] if last else series.fillna(method="bfill").iloc[0]
return series.ffill().iloc[-1] if last else series.bfill().iloc[0]


def _ts_data_valid(ts_feature, last=False):
Expand Down
2 changes: 1 addition & 1 deletion scripts/data_collector/baostock_5min/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(
@staticmethod
def calc_change(df: pd.DataFrame, last_close: float) -> pd.Series:
df = df.copy()
_tmp_series = df["close"].fillna(method="ffill")
_tmp_series = df["close"].ffill()
_tmp_shift_series = _tmp_series.shift(1)
if last_close is not None:
_tmp_shift_series.iloc[0] = float(last_close)
Expand Down
4 changes: 2 additions & 2 deletions scripts/data_collector/yahoo/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class YahooNormalize(BaseNormalize):
@staticmethod
def calc_change(df: pd.DataFrame, last_close: float) -> pd.Series:
df = df.copy()
_tmp_series = df["close"].fillna(method="ffill")
_tmp_series = df["close"].ffill()
_tmp_shift_series = _tmp_series.shift(1)
if last_close is not None:
_tmp_shift_series.iloc[0] = float(last_close)
Expand Down Expand Up @@ -459,7 +459,7 @@ def adjusted_price(self, df: pd.DataFrame) -> pd.DataFrame:
df.set_index(self._date_field_name, inplace=True)
if "adjclose" in df:
df["factor"] = df["adjclose"] / df["close"]
df["factor"] = df["factor"].fillna(method="ffill")
df["factor"] = df["factor"].ffill()
else:
df["factor"] = 1
for _col in self.COLUMNS:
Expand Down
Loading