知识卡片
数据框测试需明确数值容差
数据框比较应检查所需列、索引、类型和值,并明确浮点容差。原书用pandas._testing属私有入口,实际使用应查公开pandas.testing;样例0.009是近似,不能在未定义容差时要求它精确等于90/9990。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 软件自动化测试
原书出处 · 1 处
- · 查看原书依据
from pandas._testing import assert_frame_equal def test_normalize_columns_returns_a_dataframe_with_values_between_0_and_1(): loan_applications = pd.DataFrame({"income": [10, 100, 10000]}) result = normalize_columns(loan_applications) expected = pd.DataFrame({"income": [0, 0.009, 1]}) assert_frame_equal(expected, result) For testing dataframe equality, we use assert_frame_equal() or assert_series_equal() from pandas. By articulating our expectations of a function, we improve our understanding of the code’s behavior. In this example, we may discover that min-max normalization is the wrong data transformation to apply,