Skip to content

Commit bc36f9c

Browse files
authored
[Clean up] Use yapf to lint files; Remove dangling file links (#187)
* [Clean up] Use yapf to lint files; Remove dangling file links * indent 2 * comment indent * more comment indent
1 parent c0a41d8 commit bc36f9c

28 files changed

+1914
-1925
lines changed

cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ steps:
44
entrypoint: /bin/sh
55
args:
66
- -c
7-
- "pip3 install -r requirements.txt && python3 -m pytest"
7+
- "./run_tests.sh -p"

datacommons/core.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_property_labels(dcids, out=True):
9696
}
9797
"""
9898
# Generate the GetProperty query and send the request
99-
dcids = filter(lambda v: v==v, dcids) # Filter out NaN values
99+
dcids = filter(lambda v: v == v, dcids) # Filter out NaN values
100100
dcids = list(dcids)
101101
url = utils._API_ROOT + utils._API_ENDPOINTS['get_property_labels']
102102
payload = utils._send_request(url, req_json={'dcids': dcids})
@@ -153,18 +153,18 @@ def get_property_values(dcids,
153153
}
154154
"""
155155
# Convert the dcids field and format the request to GetPropertyValue
156-
dcids = filter(lambda v: v==v, dcids) # Filter out NaN values
156+
dcids = filter(lambda v: v == v, dcids) # Filter out NaN values
157157
dcids = list(dcids)
158158
if out:
159159
direction = 'out'
160160
else:
161161
direction = 'in'
162162

163163
req_json = {
164-
'dcids': dcids,
165-
'property': prop,
166-
'limit': limit,
167-
'direction': direction
164+
'dcids': dcids,
165+
'property': prop,
166+
'limit': limit,
167+
'direction': direction
168168
}
169169
if value_type:
170170
req_json['value_type'] = value_type
@@ -182,8 +182,8 @@ def get_property_values(dcids,
182182
if dcid in payload and 'out' in payload[dcid]:
183183
nodes = payload[dcid]['out']
184184
else:
185-
if dcid in payload and 'in' in payload[dcid]:
186-
nodes = payload[dcid]['in']
185+
if dcid in payload and 'in' in payload[dcid]:
186+
nodes = payload[dcid]['in']
187187

188188
# Add nodes to unique_results if it is not empty
189189
for node in nodes:
@@ -236,7 +236,7 @@ def get_triples(dcids, limit=utils._MAX_LIMIT):
236236
}
237237
"""
238238
# Generate the GetTriple query and send the request.
239-
dcids = filter(lambda v: v==v, dcids) # Filter out NaN values
239+
dcids = filter(lambda v: v == v, dcids) # Filter out NaN values
240240
dcids = list(dcids)
241241
url = utils._API_ROOT + utils._API_ENDPOINTS['get_triples']
242242
payload = utils._send_request(url, req_json={'dcids': dcids, 'limit': limit})
@@ -250,9 +250,7 @@ def get_triples(dcids, limit=utils._MAX_LIMIT):
250250
# Add triples as appropriate
251251
for t in payload[dcid]:
252252
if 'objectId' in t:
253-
results[dcid].append(
254-
(t['subjectId'], t['predicate'], t['objectId']))
253+
results[dcid].append((t['subjectId'], t['predicate'], t['objectId']))
255254
elif 'objectValue' in t:
256-
results[dcid].append(
257-
(t['subjectId'], t['predicate'], t['objectValue']))
255+
results[dcid].append((t['subjectId'], t['predicate'], t['objectValue']))
258256
return dict(results)

datacommons/examples/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import datacommons as dc
2424

25+
2526
def main():
2627
# Set the dcid to be that of Santa Clara County.
2728
dcids = ['geoId/06085', 'dc/p/zsb968m3v1f97']
@@ -36,8 +37,10 @@ def main():
3637

3738
# Print all property values for "containedInPlace" for Santa Clara County.
3839
print('Property Values for "containedInPlace" of Santa Clara County')
39-
prop_vals = dc.get_property_values(
40-
dcids, 'containedInPlace', out=False, value_type='City')
40+
prop_vals = dc.get_property_values(dcids,
41+
'containedInPlace',
42+
out=False,
43+
value_type='City')
4144
print('> Cities contained in {}'.format(dcids))
4245
for dcid in dcids:
4346
for city_dcid in prop_vals[dcid]:

datacommons/examples/places.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,42 @@ def main():
4242

4343
# Get place stats.
4444
print('Get place stats -- all')
45-
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'], 'dc/0hyp6tkn18vcb', obs_dates='all')
45+
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'],
46+
'dc/0hyp6tkn18vcb',
47+
obs_dates='all')
4648
print(stats)
4749

4850
print('Get place stats -- latest')
49-
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'], 'dc/0hyp6tkn18vcb')
51+
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'],
52+
'dc/0hyp6tkn18vcb')
5053
print(stats)
5154

5255
print('Get place stats -- 2014')
53-
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'], 'dc/0hyp6tkn18vcb', obs_dates=['2014'])
56+
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'],
57+
'dc/0hyp6tkn18vcb',
58+
obs_dates=['2014'])
5459
print(stats)
5560

5661
print('Get place stats -- 2014 badly formatted')
57-
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'], 'dc/0hyp6tkn18vcb', obs_dates='2014')
62+
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'],
63+
'dc/0hyp6tkn18vcb',
64+
obs_dates='2014')
5865
print(stats)
5966

6067
print('Get place stats -- 2015-2016')
61-
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'], 'dc/0hyp6tkn18vcb', obs_dates=['2015', '2016'])
68+
stats = dc.get_stats(['geoId/05', 'geoId/06', 'dc/madDcid'],
69+
'dc/0hyp6tkn18vcb',
70+
obs_dates=['2015', '2016'])
6271
print(stats)
6372

6473
# Get related places.
74+
75+
6576
# TODO(*): Fix the related places example.
6677
# print('Get related places')
6778
# related_places = dc.get_related_places(['geoId/06085'], 'Person', 'count',
6879
# 'CensusACS5yrSurvey', "measuredValue", {"gender": "Female"})
6980
# print(related_places)
7081

71-
7282
if __name__ == '__main__':
7383
main()

0 commit comments

Comments
 (0)