尝试使用breakpoint()调试pytest时,Pandas中存在不确定的DataFrame

时间:2019-06-18 22:39:28

标签: python pandas pytest python-3.7

我试图调试为什么我的一个pytest失败,并且我在pytest中使用了python3.7的breakpoint()。我有以下代码:

(Pdb) train_df 
   Acquisition_personal_win_amount            ...              yrs_since_earliest_degree
0                               -5            ...                                     -5
1                               -5            ...                                     -5
2                               -5            ...                                     -5
3                               -5            ...                                     -5
4                               -5            ...                                     -5
5                               -5            ...                                     -5
6                               -5            ...                                     -5

[7 rows x 488 columns]
(Pdb) len(train_df.columns.values)
488
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in train_df.columns.values})
*** NameError: name 'train_df' is not defined

请注意,实际上已经定义了train_df!使用列表推导会干扰pdb检测train_df存在吗?也许是pytest修补某些变量的问题?

当我尝试使用train_df.columns.values时,会发生相同的问题

(Pdb) len(train_df.columns.values)
488
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in train_df.columns.values})
*** NameError: name 'train_df' is not defined
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in [1,2,3]})
(Pdb) 

请注意,切换到简单数组[1,2,3]不会产生任何问题!

0 个答案:

没有答案