Skip to content

Commit

Permalink
Fixed pandas FutureWarning (#1073)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hubedge committed Apr 27, 2022
1 parent 00e40e7 commit 84ff662
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions qlib/contrib/report/analysis_position/parse_position.py
Expand Up @@ -68,9 +68,9 @@ def parse_position(position: dict = None) -> pd.DataFrame:
if not _trading_day_sell_df.empty:
_trading_day_sell_df["status"] = -1
_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(
date=_trading_date,
Expand Down
2 changes: 1 addition & 1 deletion qlib/contrib/report/analysis_position/risk_analysis.py
Expand Up @@ -85,7 +85,7 @@ def _get_monthly_risk_analysis_with_report(report_normal_df: pd.DataFrame) -> pd
# _m_report_long_short,
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

Expand Down
2 changes: 1 addition & 1 deletion scripts/data_collector/base.py
Expand Up @@ -170,7 +170,7 @@ def save_instrument(self, symbol, df: pd.DataFrame):
df["symbol"] = symbol
if instrument_path.exists():
_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)

def cache_small_data(self, symbol, df):
Expand Down
2 changes: 1 addition & 1 deletion scripts/data_collector/index.py
Expand Up @@ -225,7 +225,7 @@ def parse_instruments(self):
] = _row.date
else:
_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_prefix = self.INST_PREFIX.strip()
Expand Down
4 changes: 2 additions & 2 deletions scripts/data_collector/yahoo/collector.py
Expand Up @@ -245,7 +245,7 @@ def download_index_data(self):
_path = self.save_dir.joinpath(f"sh{_index_code}.csv")
if _path.exists():
_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)
time.sleep(5)

Expand Down Expand Up @@ -404,7 +404,7 @@ def normalize_yahoo(
.index
)
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)
# NOTE: The data obtained by Yahoo finance sometimes has exceptions
Expand Down

0 comments on commit 84ff662

Please sign in to comment.