18
18
19
19
20
20
def validate (df ):
21
- """Confirms that a data frame has only one date."""
21
+ """Confirm that a data frame has only one date."""
22
22
timestamps = df ['date_range_start' ].apply (date_from_timestamp )
23
23
assert len (timestamps .unique ()) == 1
24
24
25
25
26
26
def date_from_timestamp (timestamp ) -> datetime .date :
27
- """Extracts the date from a timestamp beginning with {YYYY}-{MM}-{DD}T."""
27
+ """Extract the date from a timestamp beginning with {YYYY}-{MM}-{DD}T."""
28
28
return datetime .date .fromisoformat (timestamp .split ('T' )[0 ])
29
29
30
30
31
31
def files_in_past_week (current_filename ) -> List [str ]:
32
- """Constructs file paths from previous 6 days.
32
+ """Construct file paths from previous 6 days.
33
+
33
34
Parameters
34
35
----------
35
36
current_filename: str
@@ -51,12 +52,13 @@ def files_in_past_week(current_filename) -> List[str]:
51
52
52
53
53
54
def add_suffix (signals , suffix ):
54
- """Adds `suffix` to every element of `signals`."""
55
+ """Add `suffix` to every element of `signals`."""
55
56
return [s + suffix for s in signals ]
56
57
57
58
58
59
def construct_signals (cbg_df , signal_names ):
59
60
"""Construct Census-block level signals.
61
+
60
62
In its current form, we prepare the following signals in addition to those
61
63
already available in raw form from Safegraph:
62
64
- completely_home_prop, defined as:
@@ -80,7 +82,6 @@ def construct_signals(cbg_df, signal_names):
80
82
Dataframe with columns: timestamp, county_fips, and
81
83
{each signal described above}.
82
84
"""
83
-
84
85
# Preparation
85
86
cbg_df ['county_fips' ] = (cbg_df ['origin_census_block_group' ] // MOD ).apply (
86
87
lambda x : f'{ int (x ):05d} ' )
@@ -105,6 +106,7 @@ def construct_signals(cbg_df, signal_names):
105
106
106
107
def aggregate (df , signal_names , geo_resolution = 'county' ):
107
108
"""Aggregate signals to appropriate resolution and produce standard errors.
109
+
108
110
Parameters
109
111
----------
110
112
df: pd.DataFrame
@@ -156,9 +158,10 @@ def process_window(df_list: List[pd.DataFrame],
156
158
signal_names : List [str ],
157
159
geo_resolutions : List [str ],
158
160
export_dir : str ):
159
- """Processes a list of input census block group-level data frames as a
160
- single data set and exports it. Assumes each data frame has _only_ one
161
- date of data.
161
+ """Process a list of input census block group-level data frames as a single data set and export.
162
+
163
+ Assumes each data frame has _only_ one date of data.
164
+
162
165
Parameters
163
166
----------
164
167
cbg_df: pd.DataFrame
@@ -200,8 +203,8 @@ def process(filenames: List[str],
200
203
wip_signal ,
201
204
geo_resolutions : List [str ],
202
205
export_dir : str ):
203
- """Creates and exports signals corresponding both to a single day as well
204
- as averaged over the previous week.
206
+ """Create and exports signals corresponding both single day and averaged over the previous week.
207
+
205
208
Parameters
206
209
----------
207
210
current_filename: List[str]
0 commit comments