ModelFlowIb 2.51__tar.gz → 2.53__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/PKG-INFO +1 -1
- {modelflowib-2.51 → modelflowib-2.53}/PKG-INFO +1 -1
- {modelflowib-2.51 → modelflowib-2.53}/modelclass.py +40 -17
- {modelflowib-2.51 → modelflowib-2.53}/modelgrabwf2.py +2 -1
- {modelflowib-2.51 → modelflowib-2.53}/modelreport.py +1 -1
- {modelflowib-2.51 → modelflowib-2.53}/modelwidget.py +34 -36
- {modelflowib-2.51 → modelflowib-2.53}/modelwidget_input.py +419 -279
- {modelflowib-2.51 → modelflowib-2.53}/pyproject.toml +1 -1
- {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/SOURCES.txt +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/dependency_links.txt +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/requires.txt +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/top_level.txt +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelBLfunk.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_Excel.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_cvx.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_doable.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_dynare.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_financial_stability.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_ifrs9.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_latex.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_latex_class.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/model_run_numba.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelclass2.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldash.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldashboot.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldashsidebar.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldekom.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldiff.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeldisplay.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelfeedback.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelgrab.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelhelp.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelinvert.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeljupyter.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeljupytermagic.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelmacrograb.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelmanipulation.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelmf.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelnet.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelnewton.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelnormalize.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelpattern.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelpatternrev.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelsandbox.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelsandbox_Mixin.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeltodo.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeluserfunk.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modeluserfunk_old.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelvis.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/modelwidget_shinypy.py +0 -0
- {modelflowib-2.51 → modelflowib-2.53}/setup.cfg +0 -0
|
@@ -2390,13 +2390,24 @@ class Dekomp_Mixin():
|
|
|
2390
2390
|
mfrml = model(self.allvar[varnavn]['frml'],
|
|
2391
2391
|
funks=self.funks) # calculate the formular
|
|
2392
2392
|
print_per = mfrml.smpl(start_, end_, altdf_)
|
|
2393
|
+
|
|
2394
|
+
old_start, old_end = altdf_.index.slice_locs(
|
|
2395
|
+
print_per[0], print_per[-1])
|
|
2396
|
+
new_start = max(0, old_start-1)
|
|
2397
|
+
new_end = min(len(self.basedf.index), old_end)
|
|
2398
|
+
calc_per = self.basedf.index[new_start:new_end]
|
|
2399
|
+
|
|
2400
|
+
# print(print_per)
|
|
2401
|
+
# print(calc_per)
|
|
2402
|
+
|
|
2403
|
+
|
|
2393
2404
|
vars = mfrml.allvar.keys()
|
|
2394
2405
|
varterms = [(term.var, int(term.lag) if term.lag else 0)
|
|
2395
2406
|
for term in mfrml.allvar[varnavn]['terms'] if term.var and not (term.var == varnavn and term.lag == '')]
|
|
2396
2407
|
# now we have droped dublicate terms and sorted
|
|
2397
2408
|
sterms = sorted(set(varterms), key=lambda x: varterms.index(x))
|
|
2398
2409
|
# find all the eksperiments to be performed
|
|
2399
|
-
eksperiments = [(vt, t) for vt in sterms for t in
|
|
2410
|
+
eksperiments = [(vt, t) for vt in sterms for t in calc_per]
|
|
2400
2411
|
if time_att:
|
|
2401
2412
|
...
|
|
2402
2413
|
smallalt = altdf_.loc[:, vars].copy(deep=True) # for speed
|
|
@@ -2420,10 +2431,8 @@ class Dekomp_Mixin():
|
|
|
2420
2431
|
alldf[e], e[1], e[1], silent=True) for e in eksperiments}
|
|
2421
2432
|
# dataframes with the effect of each update
|
|
2422
2433
|
diffres = {e: smallalt - allres[e] for e in eksperiments}
|
|
2423
|
-
diffres_growth = {e: smallalt.pct_change() - allres[e].pct_change() for e in eksperiments}
|
|
2424
2434
|
# we are only interested in the efect on the left hand variable
|
|
2425
2435
|
res = {e: diffres[e].loc[e[1], varnavn] for e in eksperiments}
|
|
2426
|
-
res_growth = {e: diffres_growth[e].loc[e[1], varnavn] for e in eksperiments}
|
|
2427
2436
|
# the resulting dataframe
|
|
2428
2437
|
multi = pd.MultiIndex.from_tuples([e[0] for e in eksperiments], names=[
|
|
2429
2438
|
'Variable', 'lag']).drop_duplicates()
|
|
@@ -2431,10 +2440,21 @@ class Dekomp_Mixin():
|
|
|
2431
2440
|
att_level = pd.DataFrame(index=multi, columns=print_per)
|
|
2432
2441
|
for e in eksperiments:
|
|
2433
2442
|
att_level.at[e[0], e[1]] = res[e]
|
|
2443
|
+
att_level = att_level.loc[:,print_per]
|
|
2444
|
+
|
|
2445
|
+
experiment_values_dict = {e: allres[e].loc[e[1], varnavn] for e in eksperiments}
|
|
2446
|
+
experiment_values = pd.DataFrame(index=multi, columns=calc_per).astype(float)
|
|
2447
|
+
for e in eksperiments:
|
|
2448
|
+
experiment_values.at[e[0], e[1]] = experiment_values_dict[e]
|
|
2434
2449
|
|
|
2435
|
-
|
|
2450
|
+
original_values_dict = {e: alldf[e].loc[e[1] , varnavn] for e in eksperiments}
|
|
2451
|
+
original_values = pd.DataFrame(index=multi, columns=calc_per).astype(float)
|
|
2436
2452
|
for e in eksperiments:
|
|
2437
|
-
|
|
2453
|
+
original_values.at[e[0], e[1]] = original_values_dict[e]
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
att_growth = ((original_values.pct_change(axis=1) - experiment_values.pct_change(axis=1))*100.).loc[:,print_per]
|
|
2457
|
+
|
|
2438
2458
|
|
|
2439
2459
|
# a dataframe with some summaries
|
|
2440
2460
|
diff_level = pd.DataFrame(index=multi, columns=print_per)
|
|
@@ -2462,30 +2482,33 @@ class Dekomp_Mixin():
|
|
|
2462
2482
|
|
|
2463
2483
|
|
|
2464
2484
|
#
|
|
2465
|
-
att_pct = (att_level / (difendo[print_per]) *(abs(difendo[print_per])>0.
|
|
2485
|
+
att_pct = (att_level / (difendo[print_per]) *((abs(difendo[print_per])>0.001)) * 100.).sort_values(
|
|
2466
2486
|
print_per[-1], ascending=False) # each contrinution in pct of total change
|
|
2487
|
+
# att_pct = (att_level / (difendo[print_per]) *
|
|
2488
|
+
# ((abs(difendo) > 0.001))).sort_values(
|
|
2489
|
+
# print_per[-1], ascending=False) # each contrinution in pct of total change
|
|
2467
2490
|
# breakpoint()
|
|
2468
2491
|
residual = att_pct.sum() - 100
|
|
2469
2492
|
att_pct.loc[('Total', 0), print_per] = att_pct.sum()
|
|
2470
2493
|
att_pct.loc[('Residual', 0), print_per] = residual
|
|
2471
2494
|
if lprint:
|
|
2472
2495
|
print('\nFormula :', mfrml.allvar[varnavn]['frml'], '\n')
|
|
2473
|
-
print(diff_level.to_string(
|
|
2496
|
+
print(diff_level.to_string(na_rep=' ',
|
|
2474
2497
|
float_format=lambda x: '{0:10.2f}'.format(x)))
|
|
2475
|
-
print('\n Contributions to
|
|
2476
|
-
print(att_level.to_string(
|
|
2498
|
+
print('\n Contributions to difference for ', varnavn)
|
|
2499
|
+
print(att_level.to_string(na_rep=' ',
|
|
2477
2500
|
float_format=lambda x: '{0:10.2f}'.format(x)))
|
|
2478
|
-
print('\n Share of contributions to
|
|
2479
|
-
print(att_pct.to_string(
|
|
2480
|
-
float_format=lambda x: '{0:
|
|
2501
|
+
print('\n Share of contributions to difference for ', varnavn)
|
|
2502
|
+
print(att_pct.to_string(na_rep=' ',
|
|
2503
|
+
float_format=lambda x: '{0:9.0f}%'.format(x)))
|
|
2481
2504
|
|
|
2482
2505
|
print('\n Difference in growth rate', varnavn)
|
|
2483
|
-
print(print(diff_growth.to_string(
|
|
2484
|
-
float_format=lambda x: '{0:
|
|
2506
|
+
print(print(diff_growth.to_string(na_rep=' ',
|
|
2507
|
+
float_format=lambda x: '{0:9.1f}%'.format(x))))
|
|
2485
2508
|
|
|
2486
2509
|
print('\n Contribution to growth rate', varnavn)
|
|
2487
|
-
print(att_growth.to_string(
|
|
2488
|
-
float_format=lambda x: '{0:
|
|
2510
|
+
print(att_growth.to_string(na_rep=' ',
|
|
2511
|
+
float_format=lambda x: '{0:9.1f}%'.format(x)))
|
|
2489
2512
|
|
|
2490
2513
|
att_pct = att_pct[att_pct.columns].astype(float)
|
|
2491
2514
|
dekomp_res_name = namedtuple('dekompres', 'diff_level, att_level, att_pct, ,diff_growth , att_growth')
|
|
@@ -2705,7 +2728,7 @@ class Dekomp_Mixin():
|
|
|
2705
2728
|
# # breakpoint()
|
|
2706
2729
|
# ddf0 = join_name_lag(xx[2] if pct else xx[1]).pipe(
|
|
2707
2730
|
# lambda df: df.loc[[i for i in df.index if i != 'Total'], :])
|
|
2708
|
-
print(f'{self.current_per=}')
|
|
2731
|
+
# print(f'{self.current_per=}')
|
|
2709
2732
|
ddf0 = self.get_att_pct(varnavn,lag=lag,time_att=time_att) if pct else self.get_att_level(varnavn,lag=lag)
|
|
2710
2733
|
if rename:
|
|
2711
2734
|
ddf0 = ddf0.rename(index= self.var_description)
|
|
@@ -482,7 +482,8 @@ class GrabWfModel():
|
|
|
482
482
|
rawmodel2 = rawmodel1.replace('^','**').replace('""',' ').replace('"',' ').\
|
|
483
483
|
replace('@EXP','exp').replace('@RECODE','recode').replace('@MOVAV','movavg').replace('@LOGIT','logit_inverse') \
|
|
484
484
|
.replace('@MEAN(@PC(','@AVERAGE_GROWTH((').replace('@PCY','PCT_GROWTH').replace('@PC','PCT_GROWTH')\
|
|
485
|
-
.replace('@PMAX','MAX').replace('@TREND','EVIEWS_TREND').replace('@ABS','ABS')
|
|
485
|
+
.replace('@PMAX','MAX').replace('@TREND','EVIEWS_TREND').replace('@ABS','ABS').replace('@SQRT(','SQRT(')\
|
|
486
|
+
.replace('@PMAX(','MAX(') .replace('@CNORM(','NORMCDF(')
|
|
486
487
|
# @ELEM and @DURING
|
|
487
488
|
# @ELEM and @DURING
|
|
488
489
|
rawmodel3 = nz.elem_trans(rawmodel2)
|
|
@@ -9,17 +9,20 @@ To define Jupyter widgets show variables.
|
|
|
9
9
|
import pandas as pd
|
|
10
10
|
import ipywidgets as widgets
|
|
11
11
|
|
|
12
|
-
try:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
except:
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
# try:
|
|
13
|
+
# from ipysheet import sheet, cell, current
|
|
14
|
+
# from ipysheet.pandas_loader import from_dataframe, to_dataframe
|
|
15
|
+
# except:
|
|
16
|
+
# ...
|
|
17
|
+
# print('No ipysheet ')
|
|
18
18
|
from IPython.display import display, clear_output,Latex, Markdown
|
|
19
19
|
from dataclasses import dataclass,field
|
|
20
20
|
import matplotlib.pylab as plt
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
try:
|
|
23
|
+
from ipydatagrid import DataGrid
|
|
24
|
+
except Exception as e:
|
|
25
|
+
print( 'no update sheets',e)
|
|
23
26
|
|
|
24
27
|
from modelclass import insertModelVar
|
|
25
28
|
from modelclass import model
|
|
@@ -74,41 +77,36 @@ class tabwidget:
|
|
|
74
77
|
|
|
75
78
|
@dataclass
|
|
76
79
|
class sheetwidget:
|
|
77
|
-
'''
|
|
78
|
-
df_var
|
|
79
|
-
trans
|
|
80
|
-
transpose
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
''' Class defining a widget with a data grid (using ipydatagrid) '''
|
|
81
|
+
df_var: pd.DataFrame = field(default_factory=pd.DataFrame)
|
|
82
|
+
trans: any = lambda x: x # Translation of variable names
|
|
83
|
+
transpose: bool = False # If the dataframe should be transposed
|
|
84
|
+
heading: str = ""
|
|
83
85
|
|
|
84
86
|
def __post_init__(self):
|
|
85
|
-
...
|
|
86
|
-
|
|
87
|
-
self.wexp = widgets.Label(value = self.expname,layout={'width':'54%'})
|
|
88
|
-
|
|
89
|
-
|
|
90
87
|
newnamedf = self.df_var.copy().rename(columns=self.trans)
|
|
91
|
-
self.org_df_var =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
self.
|
|
95
|
-
|
|
88
|
+
self.org_df_var = newnamedf.T if self.transpose else newnamedf
|
|
89
|
+
|
|
90
|
+
column_widths = {col: max(len(col), 10) * 9 for col in self.org_df_var.columns} # Adjust column width dynamically
|
|
91
|
+
self.data_grid = DataGrid(pd.DataFrame(self.org_df_var),
|
|
92
|
+
column_widths=column_widths, enable_filters=False,enable_sort=False,
|
|
93
|
+
editable=True, index_name = 'year')
|
|
94
|
+
self.org_values = self.org_df_var.copy()
|
|
95
|
+
|
|
96
|
+
self.datawidget = widgets.VBox([widgets.Label(value=self.heading), self.data_grid]) if len(self.heading) else self.data_grid
|
|
96
97
|
|
|
97
|
-
def update_df(self,df,current_per=None):
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
self.df_new_var.index = self.df_var.index
|
|
98
|
+
def update_df(self, df, current_per=None):
|
|
99
|
+
updated_df = pd.DataFrame(self.data_grid.data)
|
|
100
|
+
if self.transpose:
|
|
101
|
+
updated_df = updated_df.T
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
updated_df.columns = self.df_var.columns
|
|
104
|
+
updated_df.index = self.df_var.index
|
|
105
|
+
df.loc[updated_df.index, updated_df.columns] = df.loc[updated_df.index, updated_df.columns] + updated_df
|
|
105
106
|
return df
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
for c,v in zip(self.wsheet.cells,self.org_values):
|
|
110
|
-
c.value = v
|
|
111
|
-
|
|
107
|
+
|
|
108
|
+
def reset(self, g):
|
|
109
|
+
self.data_grid.data = pd.DataFrame(self.org_values)
|
|
112
110
|
|
|
113
111
|
|
|
114
112
|
@dataclass
|