-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
spark_example.py
130 lines (119 loc) · 3.71 KB
/
spark_example.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import logging
import warnings
from datetime import date, datetime
import numpy as np
import pandas as pd
from matplotlib import MatplotlibDeprecationWarning
from pyspark.sql import SparkSession
from ydata_profiling import ProfileReport
from ydata_profiling.config import Settings
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
spark_session = (
SparkSession.builder.appName("SparkProfiling").master("local[*]").getOrCreate()
)
print(spark_session.sparkContext.uiWebUrl) # noqa: T201
correlation_testdata = pd.DataFrame(
{
"test_num_1": [1, 2, 3, 5, 7, 8, 9, -100, -20, -np.inf, 3],
"test_num_2": [11, 12, 13, 15, 17, 18, 4, 1, 4, 10, 20],
"test_num_na1": [1, np.nan, 3, 5, 7, 8, np.nan, 1, np.nan, np.nan, np.nan],
"test_num_na2": [11, np.nan, 13, 15, 17, 18, 4, 11, 1, 2, 3],
"test_num_na3": [11, np.nan, 13, 15, 17, 18, 4, 11, np.nan, 4, 4],
"test_cat_1": [
"one",
"one",
"one",
"two",
"four",
"four",
"five",
"seven",
"seven",
"seven",
"one",
],
"test_cat_2": [
"one",
"one",
"two",
"two",
"three",
"four",
"four",
"two",
"seven",
None,
None,
],
"test_cat_3": [
"one",
"one",
"two",
"two",
"three",
"four",
"four",
"two",
"one",
"one",
"one",
],
"test_bool": [
True,
False,
True,
False,
True,
False,
True,
False,
True,
False,
True,
],
"test_date": [
date(2019, 5, 11),
date(2019, 5, 12),
date(2019, 5, 14),
date(2019, 5, 14),
date(2019, 5, 14),
date(2019, 5, 11),
date(2019, 5, 11),
date(2019, 5, 12),
date(2019, 5, 11),
date(2019, 5, 11),
date(2019, 5, 10),
],
"test_datetime": [datetime(2019, 5, 11, 3, 3, 3)] * 11,
}
)
upscale = 100
if upscale > 1:
correlation_testdata = pd.concat([correlation_testdata] * upscale)
correlation_data_num = spark_session.createDataFrame(correlation_testdata)
cfg = Settings()
cfg.infer_dtypes = False
cfg.correlations["auto"].calculate = False
cfg.correlations["pearson"].calculate = True
cfg.correlations["spearman"].calculate = True
cfg.interactions.continuous = False
cfg.missing_diagrams["bar"] = False
cfg.missing_diagrams["heatmap"] = False
cfg.missing_diagrams["matrix"] = False
cfg.samples.tail = 0
cfg.samples.random = 0
# Create and start the monitoring process
warnings.filterwarnings("ignore", category=MatplotlibDeprecationWarning)
a = ProfileReport(
correlation_data_num.toPandas(),
correlations={
"auto": {"calculate": True},
"pearson": {"calculate": False},
"spearman": {"calculate": False},
"kendall": {"calculate": True},
"phi_k": {"calculate": True},
"cramers": {"calculate": False},
},
)
a.to_file("test.html")