Skip to content

Commit d03cc7e

Browse files
committed
fix remaining formatting issues -- mainly long lines in comments
1 parent 9dc4f66 commit d03cc7e

18 files changed

Lines changed: 186 additions & 105 deletions

ogcore/SS.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def euler_equation_solver(guesses, *args):
3636
3737
Args:
3838
guesses (Numpy array): initial guesses for b and n, length 2S
39-
args (tuple): tuple of arguments (r, w, p_tilde, p_i, bq, TR, factor, j, p)
39+
args (tuple): tuple of arguments (r, w, p_tilde, p_i, bq, TR,
40+
factor, j, p)
4041
r (scalar): real interest rate
4142
w (scalar): real wage rate
4243
p_tilde (scalar): composite good price
@@ -294,7 +295,7 @@ def inner_loop(outer_loop_vars, p, client):
294295
schema_backup[attr] = getattr(p, attr)
295296
try:
296297
delattr(p, attr)
297-
except:
298+
except Exception:
298299
pass
299300

300301
# Scatter the parameters
@@ -304,7 +305,7 @@ def inner_loop(outer_loop_vars, p, client):
304305
for attr, value in schema_backup.items():
305306
try:
306307
setattr(p, attr, value)
307-
except:
308+
except Exception:
308309
pass
309310

310311
# Launch in parallel with submit (or map)
@@ -1144,7 +1145,8 @@ def SS_solver(
11441145
euler_savings = euler_errors[: p.S, :]
11451146
euler_labor_leisure = euler_errors[p.S :, :]
11461147
logging.info(
1147-
f"Maximum error in labor FOC = {np.absolute(euler_labor_leisure).max()}"
1148+
"Maximum error in labor FOC = "
1149+
f"{np.absolute(euler_labor_leisure).max()}"
11481150
)
11491151
logging.info(
11501152
f"Maximum error in savings FOC = {np.absolute(euler_savings).max()}"
@@ -1503,8 +1505,9 @@ def run_SS(p, client=None):
15031505
logging.warning("KeyError: previous solutions for SS not found")
15041506
use_new_guesses = True
15051507
if p.baseline or not p.reform_use_baseline_solution or use_new_guesses:
1506-
# Loop over initial guesses of r and TR until find a solution or until have
1507-
# gone through all guesses. This should usually solve in the first guess
1508+
# Loop over initial guesses of r and TR until find a solution
1509+
# or until have gone through all guesses. This should usually
1510+
# solve in the first guess
15081511
SS_solved = False
15091512
k = 0
15101513
while not SS_solved and k < len(DEV_FACTOR_LIST) - 1:

ogcore/TPI.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ def twist_doughnut(
264264
tr (Numpy array): government transfer amount
265265
theta (Numpy array): retirement replacement rates, length J
266266
factor (scalar): scaling factor converting model units to dollars
267-
ubi (Numpy array): length remaining periods of life UBI payout to household
267+
ubi (Numpy array): length remaining periods of life UBI payout
268+
to household
268269
j (int): index of ability type
269270
s (int): years of life remaining
270271
t (int): model period
@@ -773,7 +774,7 @@ def run_TPI(p, client=None):
773774
schema_backup[attr] = getattr(p, attr)
774775
try:
775776
delattr(p, attr)
776-
except:
777+
except Exception:
777778
pass
778779

779780
# Scatter the parameters
@@ -783,7 +784,7 @@ def run_TPI(p, client=None):
783784
for attr, value in schema_backup.items():
784785
try:
785786
setattr(p, attr, value)
786-
except:
787+
except Exception:
787788
pass
788789

789790
# TPI loop
@@ -821,7 +822,8 @@ def run_TPI(p, client=None):
821822
if not_done:
822823
# Some futures didn't complete in time
823824
raise TimeoutError(
824-
f"{len(not_done)} futures did not complete within 600 seconds"
825+
f"{len(not_done)} futures did not complete"
826+
" within 600 seconds"
825827
)
826828
results = client.gather(futures)
827829
except Exception as e:
@@ -1362,7 +1364,7 @@ def run_TPI(p, client=None):
13621364
I_d = aggr.get_I(
13631365
bmat_splus1[: p.T], K_d[1 : p.T + 1], K_d[: p.T], p, "TPI"
13641366
)
1365-
I = aggr.get_I(bmat_splus1[: p.T], K[1 : p.T + 1], K[: p.T], p, "TPI")
1367+
I = aggr.get_I(bmat_splus1[: p.T], K[1 : p.T + 1], K[: p.T], p, "TPI") # noqa: E741
13661368
# solve resource constraint
13671369
# foreign debt service costs
13681370
debt_service_f = fiscal.get_debt_service_f(r_p, D_f)

ogcore/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
Specify what is available to import from the ogcore package.
33
"""
44

5-
from ogcore.SS import *
6-
from ogcore.TPI import *
7-
from ogcore.aggregates import *
8-
from ogcore.constants import *
9-
from ogcore.elliptical_u_est import *
10-
from ogcore.execute import *
11-
from ogcore.firm import *
12-
from ogcore.fiscal import *
13-
from ogcore.household import *
14-
from ogcore.output_plots import *
15-
from ogcore.output_tables import *
16-
from ogcore.parameter_plots import *
17-
from ogcore.parameter_tables import *
18-
from ogcore.parameters import *
19-
from ogcore.tax import *
20-
from ogcore.txfunc import *
21-
from ogcore.utils import *
5+
from ogcore.SS import * # noqa: F403
6+
from ogcore.TPI import * # noqa: F403
7+
from ogcore.aggregates import * # noqa: F403
8+
from ogcore.constants import * # noqa: F403
9+
from ogcore.elliptical_u_est import * # noqa: F403
10+
from ogcore.execute import * # noqa: F403
11+
from ogcore.firm import * # noqa: F403
12+
from ogcore.fiscal import * # noqa: F403
13+
from ogcore.household import * # noqa: F403
14+
from ogcore.output_plots import * # noqa: F403
15+
from ogcore.output_tables import * # noqa: F403
16+
from ogcore.parameter_plots import * # noqa: F403
17+
from ogcore.parameter_tables import * # noqa: F403
18+
from ogcore.parameters import * # noqa: F403
19+
from ogcore.tax import * # noqa: F403
20+
from ogcore.txfunc import * # noqa: F403
21+
from ogcore.utils import * # noqa: F403
2222

2323
__version__ = "0.15.4"

ogcore/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
r"$\mu_{d,t}$",
171171
],
172172
"avg_earn_num_years": [
173-
"Number of years over which compute average earnings for pension benefit",
173+
"Number of years over which compute average earnings for"
174+
" pension benefit",
174175
r"$\texttt{avg\_earn\_num\_years}$",
175176
],
176177
"AIME_bkt_1": ["First AIME bracket threshold", r"$\texttt{AIME\_bkt\_1}$"],

ogcore/demographics.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def get_un_data(
7171
else: # if file not exist, prompt user for token
7272
try:
7373
UN_TOKEN = input(
74-
"Please enter your UN API token (press return if you do not have one): "
74+
"Please enter your UN API token "
75+
"(press return if you do not have one): "
7576
)
7677
# write the UN_TOKEN to a file to find in the future
7778
with open(os.path.join("un_api_token.txt"), "w") as file:
@@ -138,7 +139,8 @@ def get_un_data(
138139

139140
# Do we still want to keep the status code for failures?
140141
# print(
141-
# f"Failed to retrieve population data. HTTP status code: {response.status_code}"
142+
# "Failed to retrieve population data. HTTP status code: "
143+
# f"{response.status_code}"
142144
# )
143145
# assert False
144146

@@ -445,8 +447,9 @@ def get_pop(
445447
"47",
446448
country_id=country_id,
447449
start_year=start_year,
448-
end_year=end_year
449-
+ 2, # note go to + 2 because needed to infer immigration for end_year
450+
# note go to + 2 because needed to infer immigration
451+
# for end_year
452+
end_year=end_year + 2,
450453
)
451454
# CLean and rebin data
452455
for y in range(start_year, end_year + 2):
@@ -991,7 +994,8 @@ def get_pop_objs(
991994
assert np.allclose(pop_counter_2D, pop_2D)
992995

993996
# """"
994-
# CHANGE - in OG-Core, we are implicitly assuming pre-TP rates of mortality,
997+
# CHANGE - in OG-Core, we are implicitly assuming pre-TP rates of
998+
# mortality,
995999
# fertility, and immigration are the same as the period 0 rates.
9961000

9971001
# So let's just infer the pre-pop_dist from those.

ogcore/firm.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ def get_Y(K, K_g, L, p, method, m=-1):
2222
2323
.. math::
2424
\hat{Y}_t &= F(\hat{K}_t, \hat{K}_{g,t}, \hat{L}_t) \\
25-
&\equiv Z_t\biggl[(\gamma)^\frac{1}{\varepsilon}(\hat{K}_t)^\frac{\varepsilon-1}{\varepsilon} +
26-
(\gamma_{g})^\frac{1}{\varepsilon}(\hat{K}_{g,t})^\frac{\varepsilon-1}{\varepsilon} +
27-
(1-\gamma-\gamma_{g})^\frac{1}{\varepsilon}(\hat{L}_t)^\frac{\varepsilon-1}{\varepsilon}\biggr]^\frac{\varepsilon}{\varepsilon-1}
25+
&\equiv Z_t\biggl[
26+
(\gamma)^\frac{1}{\varepsilon}
27+
(\hat{K}_t)^\frac{\varepsilon-1}{\varepsilon} +
28+
(\gamma_{g})^\frac{1}{\varepsilon}
29+
(\hat{K}_{g,t})^\frac{\varepsilon-1}{\varepsilon} +
30+
(1-\gamma-\gamma_{g})^\frac{1}{\varepsilon}
31+
(\hat{L}_t)^\frac{\varepsilon-1}{\varepsilon}
32+
\biggr]^\frac{\varepsilon}{\varepsilon-1}
2833
\quad\forall t
2934
3035
Args:
@@ -43,7 +48,8 @@ def get_Y(K, K_g, L, p, method, m=-1):
4348

4449
if method == "SS":
4550
if m is not None:
46-
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g from prod func
51+
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g
52+
# from prod func
4753
if K_g == 0 and p.epsilon[m] <= 1:
4854
gamma_g = 0
4955
K_g = 1
@@ -75,7 +81,8 @@ def get_Y(K, K_g, L, p, method, m=-1):
7581
)
7682
) ** (epsilon / (epsilon - 1))
7783
else:
78-
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g from prod func
84+
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g
85+
# from prod func
7986
if K_g == 0 and np.any(p.epsilon) <= 1:
8087
gamma_g = p.gamma_g
8188
gamma_g[p.epsilon <= 1] = 0
@@ -100,7 +107,8 @@ def get_Y(K, K_g, L, p, method, m=-1):
100107
Y[epsilon == 1] = Y2[epsilon == 1]
101108
else: # TPI case
102109
if m is not None:
103-
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g from prod func
110+
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g
111+
# from prod func
104112
if np.any(K_g == 0) and p.epsilon[m] == 1:
105113
gamma_g = 0
106114
K_g[K_g == 0] = 1.0
@@ -132,7 +140,8 @@ def get_Y(K, K_g, L, p, method, m=-1):
132140
)
133141
) ** (epsilon / (epsilon - 1))
134142
else:
135-
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g from prod func
143+
# Set gamma_g to 0 when K_g=0 and eps=1 to remove K_g
144+
# from prod func
136145
if np.any(K_g == 0) and np.any(p.epsilon) == 1:
137146
gamma_g = p.gamma_g
138147
K_g[K_g == 0] = 1.0
@@ -649,7 +658,7 @@ def solve_L(Y, K, K_g, p, method, m=-1):
649658
if K_g == 0:
650659
K_g = 1.0
651660
gamma_g = 0
652-
except:
661+
except Exception:
653662
if np.any(K_g == 0):
654663
K_g[K_g == 0] = 1.0
655664
gamma_g = 0
@@ -673,7 +682,9 @@ def adj_cost(K, Kp1, p, method):
673682
Firm capital adjstment costs
674683
675684
..math::
676-
\Psi(K_{t}, K_{t+1}) = \frac{\psi}{2}\biggr(\frac{\biggr(\frac{I_{t}}{K_{t}}-\mu\biggl)^{2}}{\frac{I_{t}}{K_{t}}}\biggl)
685+
\Psi(K_{t}, K_{t+1}) = \frac{\psi}{2}\biggr(
686+
\frac{\biggr(\frac{I_{t}}{K_{t}}-\mu\biggl)^{2}}
687+
{\frac{I_{t}}{K_{t}}}\biggl)
677688
678689
Args:
679690
K (array-like): Current period capital stock

ogcore/fiscal.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,28 @@ def D_G_path(r, dg_fixed_values, p):
2323
2424
.. math::
2525
\begin{split}
26-
&e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\hat{D}_{t+1} + \hat{Rev}_t = (1 + r_{gov,t})\hat{D}_t + \hat{G}_t + \hat{TR}_t + \hat{UBI}_t \quad\forall t \\
26+
&e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\hat{D}_{t+1}
27+
+ \hat{Rev}_t = (1 + r_{gov,t})\hat{D}_t + \hat{G}_t
28+
+ \hat{TR}_t + \hat{UBI}_t \quad\forall t \\
2729
&\hat{G}_t = g_{g,t}\:\alpha_{g}\: \hat{Y}_t \\
2830
&\text{where}\quad g_{g,t} =
2931
\begin{cases}
30-
1 \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\:\:\text{if}\quad t < T_{G1} \\
31-
\frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\left[\rho_{d}\alpha_{D}\hat{Y}_{t} + (1-\rho_{d})\hat{D}_{t}\right] - (1+r_{gov,t})\hat{D}_{t} - \hat{TR}_{t} - \hat{UBI}_t + \hat{Rev}_{t}}{\alpha_g \hat{Y}_t} \quad\text{if}\quad T_{G1}\leq t<T_{G2} \\
32-
\frac{e^{g_y}\left(1 + \tilde{g}_{n,t+1}\right)\alpha_{D}\hat{Y}_{t} - (1+r_{gov,t})\hat{D}_{t} - \hat{TR}_{t} - \hat{UBI}_t + \hat{Rev}_{t}}{\alpha_g \hat{Y}_t} \qquad\qquad\quad\,\text{if}\quad t \geq T_{G2}
32+
1 \quad\text{if}\quad t < T_{G1} \\
33+
\frac{e^{g_y}(1+\tilde{g}_{n,t+1})[\rho_{d}\alpha_{D}
34+
\hat{Y}_{t}+(1-\rho_{d})\hat{D}_{t}]-(1+r_{gov,t})
35+
\hat{D}_{t}-\hat{TR}_{t}-\hat{UBI}_t+\hat{Rev}_{t}}
36+
{\alpha_g \hat{Y}_t}
37+
\quad\text{if}\quad T_{G1}\leq t<T_{G2} \\
38+
\frac{e^{g_y}(1+\tilde{g}_{n,t+1})\alpha_{D}\hat{Y}_{t}
39+
-(1+r_{gov,t})\hat{D}_{t}-\hat{TR}_{t}-\hat{UBI}_t
40+
+\hat{Rev}_{t}}{\alpha_g \hat{Y}_t}
41+
\quad\text{if}\quad t \geq T_{G2}
3342
\end{cases} \\
3443
&\text{and}\quad g_{tr,t} = 1 \quad\forall t \\
35-
&e^{g_y}\bigl[1 + \tilde{g}_{n,t+1}\bigr]\hat{D}^{f}_{t+1} = \hat{D}^{f}_{t} + \zeta_{D}\Bigl(e^{g_y}\bigl[1 + \tilde{g}_{n,t+1}\bigr]\hat{D}_{t+1} - \hat{D}_{t}\Bigr) \quad\forall t
44+
&e^{g_y}\bigl[1+\tilde{g}_{n,t+1}\bigr]\hat{D}^{f}_{t+1}
45+
= \hat{D}^{f}_{t} + \zeta_{D}\Bigl(e^{g_y}
46+
\bigl[1+\tilde{g}_{n,t+1}\bigr]\hat{D}_{t+1}
47+
- \hat{D}_{t}\Bigr) \quad\forall t
3648
\end{split}
3749
3850
Args:
@@ -203,7 +215,8 @@ def get_D_ss(r_gov, Y, p):
203215
\bar{D} &= \alpha_D \bar{Y}\\
204216
\bar{D_d} &= \bar{D} - \bar{D}^{f}\\
205217
\bar{D_f} &= \zeta_{D}\bar{D} \\
206-
\overline{\text{new borrowing}} &= (e^{g_{y}}(1 + \bar{g}_n) - 1)\bar{D}\\
218+
\overline{\text{new borrowing}} &=
219+
(e^{g_{y}}(1 + \bar{g}_n) - 1)\bar{D}\\
207220
\overline{\text{debt service}} &= \bar{r}_{gov}\bar{D} \\
208221
\overline{\text{new foreign borrowing}} &=
209222
(e^{g_{y}}(1 + \bar{g}_n) - 1)\bar{D_f}\\
@@ -361,14 +374,17 @@ def get_r_gov(r, DY_ratio, p, method, t=0):
361374
Determine the interest rate on government debt
362375
363376
.. math::
364-
r_{gov,t} = \max\{(1-\tau_{d,t}r_{t} - \mu_d + \beta_1 \frac{D_t}{Y_t} + \beta_2 \left(\frac{D_t}{Y_t}\right)^2, 0.0\}
377+
r_{gov,t} = \max\{(1-\tau_{d,t}r_{t} - \mu_d
378+
+ \beta_1 \frac{D_t}{Y_t}
379+
+ \beta_2 \left(\frac{D_t}{Y_t}\right)^2, 0.0\}
365380
366381
Args:
367382
r (array_like): interest rate on private capital debt over the
368383
time path or in the steady state
369384
DY_ratio (array_like): ratio of government debt to GDP
370385
p (OG-Core Specifications object): model parameters
371-
method (str): either 'scalar' for one period or 'TPI' for transition path
386+
method (str): either 'scalar' for one period or 'TPI' for
387+
transition path
372388
t (int): time period index, used only if method is 'scalar'
373389
374390
Returns:

ogcore/household.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ def get_cons(
303303
+ \hat{w}_t e_{j,s}n_{j,s,t} + \hat{bq}_{j,s,t} + \hat{rm}_{j,s,t}
304304
+ \hat{tr}_{j,s,t} + \hat{ubi}_{j,s,t} + \hat{pension}_{j,s,t}
305305
- \hat{tax}_{j,s,t} \\
306-
&\qquad - \sum_{i=1}^I\left(1 + \tau^c_{i,t}\right)p_{i,t}\hat{c}_{min,i}
306+
&\qquad - \sum_{i=1}^I\left(1 + \tau^c_{i,t}\right)
307+
p_{i,t}\hat{c}_{min,i}
307308
- e^{g_y}\hat{b}_{j,s+1,t+1}\biggr] / p_t \\
308309
&\qquad\qquad\forall j,t \quad\text{and}\quad E+1\leq s\leq E+S
309310
\quad\text{where}\quad \hat{b}_{j,E+1,t}=0
@@ -380,7 +381,7 @@ def get_ci(c_s, p_i, p_tilde, tau_c, alpha_c, c_min, method="SS"):
380381
c_si (array_like): consumption of good i
381382
"""
382383
if method == "SS":
383-
I = alpha_c.shape[0]
384+
I = alpha_c.shape[0] # noqa: E741
384385
S = c_s.shape[0]
385386
J = c_s.shape[1]
386387
tau_c = tau_c.reshape(I, 1, 1)
@@ -391,7 +392,7 @@ def get_ci(c_s, p_i, p_tilde, tau_c, alpha_c, c_min, method="SS"):
391392
c_s = c_s.reshape(1, S, J)
392393
c_si = alpha_c * (((1 + tau_c) * p_i) / p_tilde) ** (-1) * c_s + c_min
393394
else: # Time path case
394-
I = alpha_c.shape[0]
395+
I = alpha_c.shape[0] # noqa: E741
395396
T = p_i.shape[0]
396397
S = c_s.shape[1]
397398
J = c_s.shape[2]
@@ -876,11 +877,13 @@ def constraint_checker_TPI(b_dist, n_dist, c_dist, t, ltilde):
876877
"""
877878
if (b_dist <= 0).any():
878879
logging.info(
879-
f"WARNING: Aggregate capital is less than or equal to zero in period {t}."
880+
"WARNING: Aggregate capital is less than or equal to"
881+
f" zero in period {t}."
880882
)
881883
if (n_dist < 0).any():
882884
logging.info(
883-
f"WARNING: Labor supply violates nonnegativity constraints in period {t}."
885+
"WARNING: Labor supply violates nonnegativity"
886+
f" constraints in period {t}."
884887
)
885888
if (n_dist > ltilde).any():
886889
logging.info(

ogcore/parameter_plots.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def plot_ability_profiles(
210210
211211
Args:
212212
p (OG-Core Specifications class): parameters object
213-
t (int): model period for year, if None, then plot ability matrix for SS
213+
t (int): model period for year, if None, then plot ability
214+
matrix for SS
214215
log_scale (bool): whether to plot in log points
215216
include_title (bool): whether to include a title in the plot
216217
path (string): path to save figure to
@@ -1197,9 +1198,9 @@ def plot_2D_taxfunc(
11971198
if age is not None:
11981199
assert isinstance(age, int)
11991200
assert age >= E
1200-
s = (
1201-
age - E
1202-
) # Note: assumed age is given in E + model periods (but age below is also assumed to be calendar years)
1201+
# Note: assumed age is given in E + model periods (but age
1202+
# below is also assumed to be calendar years)
1203+
s = age - E
12031204
else:
12041205
s = 0 # if not age-specific, all ages have the same values
12051206
t = year - start_year

0 commit comments

Comments
 (0)