Skip to content

Commit 8a772f7

Browse files
committed
version 0.2.1
1 parent b694995 commit 8a772f7

3 files changed

Lines changed: 46 additions & 31 deletions

File tree

regcensus/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
date_format = re.compile(r'\d{4}(?:-\d{2}-\d{2})?')
99

10-
URL = 'http://ec2-18-214-181-163.compute-1.amazonaws.com'
10+
URL = 'https://api.quantgov.org'
1111

1212

1313
def get_values(series, jurisdiction, date, filtered=True, summary=True,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='regcensus',
7-
version='0.2.0',
7+
version='0.2.1',
88
description='Python package for accessing data from the QuantGov API',
99
url='https://github.com/QuantGov/regcensus-api-python',
1010
author='QuantGov',

tests/test_api.py

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,60 @@
44

55

66
# UTILITY FUNCTIONS
7-
def order_results(results, column):
8-
return list(results[column].sort_values().head(10).values)
7+
def order_results(results, column, descending=False):
8+
if descending:
9+
return list(reversed(results[column].sort_values().tail(10).values))
10+
else:
11+
return list(results[column].sort_values().head(10).values)
912

1013

1114
# TEST FUNCTIONS
1215
def test_get_series():
13-
results = rc.get_series()
16+
results = rc.get_series(verbose=1)
1417
assert order_results(results, 'seriesCode') == [
1518
'NY.GDP.MKTP.CD', 'NY.GDP.MKTP.KD', 'NY.GDP.MKTP.KD.ZG',
16-
'NY.GDP.PCAP.KD.ZG', 'RG_OCL1000002A', 'RG_OCLI1000001A',
17-
'RG_QLTY1000470Z', 'RG_QLTY1000471Z',
18-
'RG_QLTY1000472Z', 'RG_QLTY1000473Z'
19+
'NY.GDP.PCAP.KD.ZG', 'RG_DRST0000001A', 'RG_HLC1000002A',
20+
'RG_OCL1000002A', 'RG_OCL1000002B', 'RG_OCL1000002C', 'RG_OCLI1000001A'
1921
]
2022

2123

2224
def test_get_agencies():
23-
results = rc.get_agencies(38)
25+
results = rc.get_agencies(38, verbose=1)
2426
assert order_results(results, 'agencyID') == [
25-
64, 65, 66, 67, 68, 69, 70, 71, 72, 73
27+
64, 65, 66, 67, 68, 70, 71, 72, 73, 74
2628
]
2729

2830

2931
def test_get_jurisdictions():
30-
results = rc.get_jurisdictions()
32+
results = rc.get_jurisdictions(verbose=1)
3133
assert order_results(results, 'jurisdictionID') == [
3234
2, 4, 10, 11, 14, 15, 17, 20, 23, 24
3335
]
3436

3537

3638
def test_get_periods():
37-
results = rc.get_periods()
38-
assert order_results(results, 'seresYearID') == [
39-
102994, 102995, 102996, 102997, 102998,
40-
102999, 103000, 103001, 103002, 103003
39+
results = rc.get_periods(38, verbose=1)
40+
assert order_results(results, 'recordsAvailable', descending=True) == [
41+
30696278, 30696278, 30696278, 30696278, 30696278,
42+
30696278, 30696278, 30696278, 30696278, 30696278
4143
]
4244

4345

46+
def test_get_periods_one_series():
47+
results = rc.get_periods(38, seriesID=19, verbose=1)
48+
assert order_results(results, 'recordsAvailable') == [16796, 16796]
49+
50+
4451
def test_get_industries():
45-
results = rc.get_industries(jurisdictionID=38)
52+
results = rc.get_industries(jurisdictionID=38, verbose=1)
4653
assert order_results(results, 'industryCode') == [
4754
'0', '11', '111', '1111', '11111', '111110',
4855
'11112', '111120', '11113', '111130'
4956
]
5057

5158

5259
def test_get_documents():
53-
results = rc.get_documents(jurisdictionID=44)
60+
results = rc.get_documents(jurisdictionID=44, verbose=1)
5461
assert order_results(results, 'documentID') == [
5562
4441363, 4441364, 4441365, 4441366, 4441367,
5663
4441368, 4441369, 4441370, 4441371, 4441372
@@ -82,10 +89,10 @@ def test_get_values_all_industries():
8289
series=9, jurisdiction=58, date=2019, industry='all', filtered=False
8390
)
8491
assert order_results(results, 'seriesValue') == [
85-
16.487800191811402, 28.080800290597836, 36.27130037093593,
86-
36.53810011051246, 40.113500030507566, 45.02970027324045,
87-
48.842899827621295, 50.17920009633963, 72.05880061667267,
88-
82.19629916545819
92+
16.487800191811402, 28.080800290597836, 32.408500283963804,
93+
36.27130037093593, 36.53810011051246, 36.72170047096006,
94+
40.113500030507566, 44.19190023323608, 45.02970027324045,
95+
48.842899827621295
8996
]
9097

9198

@@ -100,11 +107,14 @@ def test_get_values_multiple_industries():
100107

101108
def test_get_values_one_industry():
102109
results = rc.get_values(
103-
series=9, jurisdiction=58, date='2019-05-15',
110+
series=9, jurisdiction=20, date='2020-06-02',
104111
industry='111', summary=False
105112
)
106-
assert order_results(results, 'seriesValue') == [
107-
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
113+
assert order_results(results, 'seriesValue', descending=True) == [
114+
208.5117055773735, 177.00449323654175, 86.01110327243805,
115+
76.680001989007, 66.70080256462097, 61.46759942173958,
116+
58.94939732551575, 41.14539943635464, 36.53759956359863,
117+
33.51419833302498
108118
]
109119

110120

@@ -140,7 +150,7 @@ def test_get_values_incorrect_dates(capsys):
140150
def test_get_values_country():
141151
results = rc.get_values(series=1, jurisdiction=38, date=2019, country=True)
142152
assert order_results(results, 'seriesValue') == [
143-
43940.0, 52569.0, 60086.0, 63203.0, 63735.0,
153+
43940.0, 51925.0, 52569.0, 60086.0, 63735.0,
144154
70969.0, 78676.0, 92522.0, 104562.0, 107063.0
145155
]
146156

@@ -187,21 +197,26 @@ def test_get_values_error(capsys):
187197
results = rc.get_values(series=1, jurisdiction=38, date=1900)
188198
assert not results
189199
assert capsys.readouterr().out == (
190-
'WARNING: SeriesValue was not found for the specified parameters'
191-
'{parameters={jurisdiction=[38], date=[1900], industry=null, '
192-
'agency=null, dateIsRange=false, filteredOnly=true, summary=true, '
193-
'documentType=3, documentID=null}}\n'
200+
'WARNING: SeriesValue was not found for the specified parameters. '
201+
'Please check that you have selected the right combination of '
202+
'parameters. When in doubt, please use the /periods endpoint to '
203+
'find out the combinations of series, jurisdiction, periods, '
204+
'agencies, document types for which there are data available.'
205+
'{parameters={jurisdiction=[US_UNITED_STATES], date=[1900], '
206+
'industry=null, agency=null, dateIsRange=false, filteredOnly=true, '
207+
'summary=true, series=[SERIES_1], documentType=ALL_REGULATIONS, '
208+
'documentID=null}}\n'
194209
)
195210

196211

197212
def test_list_document_types():
198213
results = rc.list_document_types()
199-
assert results['All Regulations'] == 3
214+
assert results['Regulation text: All regulations'] == 3
200215

201216

202217
def test_list_series():
203218
results = rc.list_series()
204-
assert results['Conditionals'] == 135
219+
assert results['Complexity: Conditionals analysis'] == 135
205220

206221

207222
def test_list_agencies():

0 commit comments

Comments
 (0)