-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.py
More file actions
94 lines (91 loc) · 3.26 KB
/
validation.py
File metadata and controls
94 lines (91 loc) · 3.26 KB
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
import pandera as pa
# Schema for MTA Daily Ridership Data
mta_schema = pa.DataFrameSchema(
{
"date": pa.Column(
pa.DateTime,
nullable=False,
checks=pa.Check.greater_than_or_equal_to("2020-03-01"),
description="Date of ridership record, starting from March 2020",
),
"subways_total_estimated_ridership": pa.Column(
float,
nullable=True,
checks=pa.Check.greater_than_or_equal_to(0),
description="Total estimated subway ridership",
),
"subways_of_comparable_pre_pandemic_day": pa.Column(
float,
nullable=True,
checks=[
pa.Check.greater_than_or_equal_to(0),
pa.Check.less_than_or_equal_to(2.0),
],
description="Subway ridership as ratio of pre-pandemic levels (0 to 2.0)",
),
"buses_total_estimated_ridership": pa.Column(
float,
nullable=True,
checks=pa.Check.greater_than_or_equal_to(0),
description="Total estimated bus ridership",
),
"buses_of_comparable_pre_pandemic_day": pa.Column(
float,
nullable=True,
checks=[
pa.Check.greater_than_or_equal_to(0),
pa.Check.less_than_or_equal_to(2.0),
],
description="Bus ridership as ratio of pre-pandemic levels",
),
"lirr_total_estimated_ridership": pa.Column(
float,
nullable=True,
checks=pa.Check.greater_than_or_equal_to(0),
description="Total estimated LIRR ridership",
),
"lirr_of_comparable_pre_pandemic_day": pa.Column(
float,
nullable=True,
checks=[
pa.Check.greater_than_or_equal_to(0),
pa.Check.less_than_or_equal_to(2.0),
],
description="LIRR ridership as ratio of pre-pandemic levels",
),
"metro_north_total_estimated_ridership": pa.Column(
float,
nullable=True,
checks=pa.Check.greater_than_or_equal_to(0),
description="Total estimated Metro-North ridership",
),
"metro_north_of_comparable_pre_pandemic_day": pa.Column(
float,
nullable=True,
checks=[
pa.Check.greater_than_or_equal_to(0),
pa.Check.less_than_or_equal_to(2.0),
],
description="Metro-North ridership as ratio of pre-pandemic levels",
),
"bridges_and_tunnels_total_traffic": pa.Column(
float,
nullable=True,
checks=pa.Check.greater_than_or_equal_to(0),
description="Total bridges and tunnels traffic",
),
"bridges_and_tunnels_of_comparable_pre_pandemic_day": pa.Column(
float,
nullable=True,
checks=[
pa.Check.greater_than_or_equal_to(0),
pa.Check.less_than_or_equal_to(2.0),
],
description="B&T traffic as ratio of pre-pandemic levels",
),
},
coerce=True,
)
def validate_mta_data(df):
"""Validate MTA ridership dataframe against schema."""
return mta_schema.validate(df)