mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 15:26:54 +08:00
suppress the SettingWithCopyWarning of pandas (#1513)
* df value is set as expected, suppress the warning; * depress warning with pandas option_context --------- Co-authored-by: Cadenza-Li <362237642@qq.com>
This commit is contained in:
@@ -318,9 +318,13 @@ class CSZScoreNorm(Processor):
|
|||||||
# try not modify original dataframe
|
# try not modify original dataframe
|
||||||
if not isinstance(self.fields_group, list):
|
if not isinstance(self.fields_group, list):
|
||||||
self.fields_group = [self.fields_group]
|
self.fields_group = [self.fields_group]
|
||||||
for g in self.fields_group:
|
# depress warning by references:
|
||||||
cols = get_group_columns(df, g)
|
# https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas
|
||||||
df[cols] = df[cols].groupby("datetime", group_keys=False).apply(self.zscore_func)
|
# https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html#getting-and-setting-options
|
||||||
|
with pd.option_context("mode.chained_assignment", None):
|
||||||
|
for g in self.fields_group:
|
||||||
|
cols = get_group_columns(df, g)
|
||||||
|
df[cols] = df[cols].groupby("datetime", group_keys=False).apply(self.zscore_func)
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user