Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_process_data.py 1.8 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  1. import pandas as pd
  2. from pandas.testing import assert_frame_equal
  3. from src.process_data import (get_age, get_enrollment_years, get_family_size,
  4. get_total_purchases, scale_features)
  5. def test_get_age():
  6. df = pd.DataFrame({"Year_Birth": [1999, 2000]})
  7. assert_frame_equal(
  8. get_age(df),
  9. pd.DataFrame({"Year_Birth": [1999, 2000], "age": [22, 21]}),
  10. )
  11. def test_get_total_purchases():
  12. df = pd.DataFrame({"FirstPurchases": [1, 2], "SecondPurchases": [3, 4]})
  13. out = get_total_purchases(df)
  14. assert out["total_purchases"].tolist() == [4, 6]
  15. def test_get_enrollment_years():
  16. df = pd.DataFrame({"Dt_Customer": ["04-09-2012"]})
  17. assert_frame_equal(
  18. get_enrollment_years(df),
  19. pd.DataFrame(
  20. {
  21. "Dt_Customer": [pd.Timestamp("2012-04-09 00:00:00")],
  22. "enrollment_years": [10],
  23. }
  24. ),
  25. )
  26. def test_scale_features():
  27. df = pd.DataFrame(
  28. {"FirstPurchases": [1, 2, 5], "SecondPurchases": [3, 4, 7]}
  29. )
  30. out = scale_features.run(df)
  31. assert_frame_equal(
  32. out,
  33. pd.DataFrame(
  34. {
  35. "FirstPurchases": [-0.980, -0.392, 1.373],
  36. "SecondPurchases": [-0.980, -0.392, 1.373],
  37. }
  38. ),
  39. atol=2,
  40. )
  41. def test_get_family_size():
  42. df = pd.DataFrame(
  43. {
  44. "Marital_Status": ["Married", "Absurd", "Single"],
  45. "total_children": [1, 2, 3],
  46. }
  47. )
  48. assert_frame_equal(
  49. get_family_size(df, {"Married": 2, "Absurd": 1, "Single": 1}),
  50. pd.DataFrame(
  51. {
  52. "Marital_Status": ["Married", "Absurd", "Single"],
  53. "total_children": [1, 2, 3],
  54. "family_size": [3, 3, 4],
  55. }
  56. ),
  57. )
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...