Skip to content

Commit 69e28ce

Browse files
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 <[email protected]>
1 parent 4c30e58 commit 69e28ce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

qlib/data/dataset/processor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,13 @@ def __call__(self, df):
318318
# try not modify original dataframe
319319
if not isinstance(self.fields_group, list):
320320
self.fields_group = [self.fields_group]
321-
for g in self.fields_group:
322-
cols = get_group_columns(df, g)
323-
df[cols] = df[cols].groupby("datetime", group_keys=False).apply(self.zscore_func)
321+
# depress warning by references:
322+
# https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas
323+
# https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html#getting-and-setting-options
324+
with pd.option_context("mode.chained_assignment", None):
325+
for g in self.fields_group:
326+
cols = get_group_columns(df, g)
327+
df[cols] = df[cols].groupby("datetime", group_keys=False).apply(self.zscore_func)
324328
return df
325329

326330

0 commit comments

Comments
 (0)