mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-14 16:26:55 +08:00
Fixed pandas FutureWarning (#1073)
* Fixed pandas FutureWarning `FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.` * fixed another pandas FutureWarning ``` scripts/data_collector/index.py:228: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. new_df = new_df.append(_tmp_df, sort=False) ``` * fixed more pandas futurewarnings
This commit is contained in:
@@ -68,9 +68,9 @@ def parse_position(position: dict = None) -> pd.DataFrame:
|
|||||||
if not _trading_day_sell_df.empty:
|
if not _trading_day_sell_df.empty:
|
||||||
_trading_day_sell_df["status"] = -1
|
_trading_day_sell_df["status"] = -1
|
||||||
_trading_day_sell_df["date"] = _trading_date
|
_trading_day_sell_df["date"] = _trading_date
|
||||||
_trading_day_df = _trading_day_df.append(_trading_day_sell_df, sort=False)
|
_trading_day_df = pd.concat([_trading_day_df, _trading_day_sell_df], sort=False)
|
||||||
|
|
||||||
result_df = result_df.append(_trading_day_df, sort=True)
|
result_df = pd.concat([result_df, _trading_day_df], sort=True)
|
||||||
|
|
||||||
previous_data = dict(
|
previous_data = dict(
|
||||||
date=_trading_date,
|
date=_trading_date,
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ def _get_monthly_risk_analysis_with_report(report_normal_df: pd.DataFrame) -> pd
|
|||||||
# _m_report_long_short,
|
# _m_report_long_short,
|
||||||
pd.Timestamp(year=gp_m[0], month=gp_m[1], day=month_days),
|
pd.Timestamp(year=gp_m[0], month=gp_m[1], day=month_days),
|
||||||
)
|
)
|
||||||
_monthly_df = _monthly_df.append(_temp_df, sort=False)
|
_monthly_df = pd.concat([_monthly_df, _temp_df], sort=False)
|
||||||
|
|
||||||
return _monthly_df
|
return _monthly_df
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class BaseCollector(abc.ABC):
|
|||||||
df["symbol"] = symbol
|
df["symbol"] = symbol
|
||||||
if instrument_path.exists():
|
if instrument_path.exists():
|
||||||
_old_df = pd.read_csv(instrument_path)
|
_old_df = pd.read_csv(instrument_path)
|
||||||
df = _old_df.append(df, sort=False)
|
df = pd.concat([_old_df, df], sort=False)
|
||||||
df.to_csv(instrument_path, index=False)
|
df.to_csv(instrument_path, index=False)
|
||||||
|
|
||||||
def cache_small_data(self, symbol, df):
|
def cache_small_data(self, symbol, df):
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ class IndexBase:
|
|||||||
] = _row.date
|
] = _row.date
|
||||||
else:
|
else:
|
||||||
_tmp_df = pd.DataFrame([[_row.symbol, self.bench_start_date, _row.date]], columns=instruments_columns)
|
_tmp_df = pd.DataFrame([[_row.symbol, self.bench_start_date, _row.date]], columns=instruments_columns)
|
||||||
new_df = new_df.append(_tmp_df, sort=False)
|
new_df = pd.concat([new_df, _tmp_df], sort=False)
|
||||||
|
|
||||||
inst_df = new_df.loc[:, instruments_columns]
|
inst_df = new_df.loc[:, instruments_columns]
|
||||||
_inst_prefix = self.INST_PREFIX.strip()
|
_inst_prefix = self.INST_PREFIX.strip()
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class YahooCollectorCN1d(YahooCollectorCN):
|
|||||||
_path = self.save_dir.joinpath(f"sh{_index_code}.csv")
|
_path = self.save_dir.joinpath(f"sh{_index_code}.csv")
|
||||||
if _path.exists():
|
if _path.exists():
|
||||||
_old_df = pd.read_csv(_path)
|
_old_df = pd.read_csv(_path)
|
||||||
df = _old_df.append(df, sort=False)
|
df = pd.concat([_old_df, df], sort=False)
|
||||||
df.to_csv(_path, index=False)
|
df.to_csv(_path, index=False)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ class YahooNormalize(BaseNormalize):
|
|||||||
.index
|
.index
|
||||||
)
|
)
|
||||||
df.sort_index(inplace=True)
|
df.sort_index(inplace=True)
|
||||||
df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]), set(df.columns) - {symbol_field_name}] = np.nan
|
df.loc[(df["volume"] <= 0) | np.isnan(df["volume"]), list(set(df.columns) - {symbol_field_name})] = np.nan
|
||||||
|
|
||||||
change_series = YahooNormalize.calc_change(df, last_close)
|
change_series = YahooNormalize.calc_change(df, last_close)
|
||||||
# NOTE: The data obtained by Yahoo finance sometimes has exceptions
|
# NOTE: The data obtained by Yahoo finance sometimes has exceptions
|
||||||
|
|||||||
Reference in New Issue
Block a user