我正在使用假设来测试数据帧,当它们“空”时,我会遇到一些意想不到的行为。
在下面的示例中,我有一个包含所有 nans 的数据框,它被视为一个NoneType
对象而不是数据框(因此它没有属性notnull()
):
Falsifying example: test_merge_csvs_properties(input_df_dict= {'googletrend.csv': file week trend
0 NaN NaN NaN
1 NaN NaN NaN
2 NaN NaN NaN
3 NaN NaN NaN
4 NaN NaN NaN 5 NaN NaN NaN}
<snip>
Traceback (most recent call last):
File "/home/chachi/Capstone-SalesForecasting/tests/test_make_dataset_with_composite.py", line 285, in test_merge_csvs_properties
input_dataframe, df_dict = make_dataset.merge_csvs(input_df_dict)
File "/home/chachi/Capstone-SalesForecasting/tests/../src/data/make_dataset.py", line 238, in merge_csvs
if dfs_dict['googletrend.csv'].notnull().any().any():
AttributeError: 'NoneType' object has no attribute 'notnull'
与 ipython 会话相比,其中所有 nans 的数据帧仍然是数据帧:
>>> import pandas as pd
>>> import numpy as np
>>> tester = pd.DataFrame({'test': [np.NaN]})
>>> tester
test
0 NaN
>>> tester.notnull().any().any()
False
我正在明确测试notnull()
以允许各种病理示例。有什么建议么?