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.
Files changed (51) hide show
  1. {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/PKG-INFO +1 -1
  2. {modelflowib-2.51 → modelflowib-2.53}/PKG-INFO +1 -1
  3. {modelflowib-2.51 → modelflowib-2.53}/modelclass.py +40 -17
  4. {modelflowib-2.51 → modelflowib-2.53}/modelgrabwf2.py +2 -1
  5. {modelflowib-2.51 → modelflowib-2.53}/modelreport.py +1 -1
  6. {modelflowib-2.51 → modelflowib-2.53}/modelwidget.py +34 -36
  7. {modelflowib-2.51 → modelflowib-2.53}/modelwidget_input.py +419 -279
  8. {modelflowib-2.51 → modelflowib-2.53}/pyproject.toml +1 -1
  9. {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/SOURCES.txt +0 -0
  10. {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/dependency_links.txt +0 -0
  11. {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/requires.txt +0 -0
  12. {modelflowib-2.51 → modelflowib-2.53}/ModelFlowIb.egg-info/top_level.txt +0 -0
  13. {modelflowib-2.51 → modelflowib-2.53}/modelBLfunk.py +0 -0
  14. {modelflowib-2.51 → modelflowib-2.53}/model_Excel.py +0 -0
  15. {modelflowib-2.51 → modelflowib-2.53}/model_cvx.py +0 -0
  16. {modelflowib-2.51 → modelflowib-2.53}/model_doable.py +0 -0
  17. {modelflowib-2.51 → modelflowib-2.53}/model_dynare.py +0 -0
  18. {modelflowib-2.51 → modelflowib-2.53}/model_financial_stability.py +0 -0
  19. {modelflowib-2.51 → modelflowib-2.53}/model_ifrs9.py +0 -0
  20. {modelflowib-2.51 → modelflowib-2.53}/model_latex.py +0 -0
  21. {modelflowib-2.51 → modelflowib-2.53}/model_latex_class.py +0 -0
  22. {modelflowib-2.51 → modelflowib-2.53}/model_run_numba.py +0 -0
  23. {modelflowib-2.51 → modelflowib-2.53}/modelclass2.py +0 -0
  24. {modelflowib-2.51 → modelflowib-2.53}/modeldash.py +0 -0
  25. {modelflowib-2.51 → modelflowib-2.53}/modeldashboot.py +0 -0
  26. {modelflowib-2.51 → modelflowib-2.53}/modeldashsidebar.py +0 -0
  27. {modelflowib-2.51 → modelflowib-2.53}/modeldekom.py +0 -0
  28. {modelflowib-2.51 → modelflowib-2.53}/modeldiff.py +0 -0
  29. {modelflowib-2.51 → modelflowib-2.53}/modeldisplay.py +0 -0
  30. {modelflowib-2.51 → modelflowib-2.53}/modelfeedback.py +0 -0
  31. {modelflowib-2.51 → modelflowib-2.53}/modelgrab.py +0 -0
  32. {modelflowib-2.51 → modelflowib-2.53}/modelhelp.py +0 -0
  33. {modelflowib-2.51 → modelflowib-2.53}/modelinvert.py +0 -0
  34. {modelflowib-2.51 → modelflowib-2.53}/modeljupyter.py +0 -0
  35. {modelflowib-2.51 → modelflowib-2.53}/modeljupytermagic.py +0 -0
  36. {modelflowib-2.51 → modelflowib-2.53}/modelmacrograb.py +0 -0
  37. {modelflowib-2.51 → modelflowib-2.53}/modelmanipulation.py +0 -0
  38. {modelflowib-2.51 → modelflowib-2.53}/modelmf.py +0 -0
  39. {modelflowib-2.51 → modelflowib-2.53}/modelnet.py +0 -0
  40. {modelflowib-2.51 → modelflowib-2.53}/modelnewton.py +0 -0
  41. {modelflowib-2.51 → modelflowib-2.53}/modelnormalize.py +0 -0
  42. {modelflowib-2.51 → modelflowib-2.53}/modelpattern.py +0 -0
  43. {modelflowib-2.51 → modelflowib-2.53}/modelpatternrev.py +0 -0
  44. {modelflowib-2.51 → modelflowib-2.53}/modelsandbox.py +0 -0
  45. {modelflowib-2.51 → modelflowib-2.53}/modelsandbox_Mixin.py +0 -0
  46. {modelflowib-2.51 → modelflowib-2.53}/modeltodo.py +0 -0
  47. {modelflowib-2.51 → modelflowib-2.53}/modeluserfunk.py +0 -0
  48. {modelflowib-2.51 → modelflowib-2.53}/modeluserfunk_old.py +0 -0
  49. {modelflowib-2.51 → modelflowib-2.53}/modelvis.py +0 -0
  50. {modelflowib-2.51 → modelflowib-2.53}/modelwidget_shinypy.py +0 -0
  51. {modelflowib-2.51 → modelflowib-2.53}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ModelFlowIb
3
- Version: 2.51
3
+ Version: 2.53
4
4
  Summary: A tool to solve and manage dynamic economic models
5
5
  Author-email: Ib Hansen <your@email.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ModelFlowIb
3
- Version: 2.51
3
+ Version: 2.53
4
4
  Summary: A tool to solve and manage dynamic economic models
5
5
  Author-email: Ib Hansen <your@email.com>
6
6
  License: MIT
@@ -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 print_per]
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
- att_growth = pd.DataFrame(index=multi, columns=print_per)
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
- att_growth.at[e[0], e[1]] = res_growth[e]*100.
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.000001) * 100).sort_values(
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 differende for ', varnavn)
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 differende for ', varnavn)
2479
- print(att_pct.to_string(
2480
- float_format=lambda x: '{0:10.0f}%'.format(x)))
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:10.1f}%'.format(x))))
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:10.1f}%'.format(x)))
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)
@@ -279,7 +279,7 @@ class Options:
279
279
  chunk_size: int = 0
280
280
  timeslice: List = field(default_factory=list)
281
281
  max_cols: int = 6
282
- last_cols: int = 1
282
+ last_cols: int = 3
283
283
 
284
284
  ncol : int = 2
285
285
  samefig :bool = False
@@ -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
- from ipysheet import sheet, cell, current
14
- from ipysheet.pandas_loader import from_dataframe, to_dataframe
15
- except:
16
- ...
17
- # print('No ipysheet in notebook version 7')
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
- ''' class defining a widget which updates from a sheet '''
78
- df_var : pd.DataFrame = field(default_factory=pd.DataFrame) # definition
79
- trans : any = lambda x : x # renaming of variables
80
- transpose : bool = False # orientation of dataframe
81
- expname : str = "Carbon tax rate, US$ per tonn "
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 = self.newnamedf.T if self.transpose else newnamedf
92
-
93
- self.wsheet = sheet(from_dataframe(self.org_df_var),column_resizing=True)
94
- self.org_values = [c.value for c in self.wsheet.cells]
95
- self.datawidget=widgets.VBox([self.wexp,self.wsheet]) if len(self.expname) else self.wsheet
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
- # breakpoint()
99
- self.df_new_var = to_dataframe(self.wsheet).T if self.transpose else to_dataframe(self.wsheet)
100
- self.df_new_var.columns = self.df_var.columns
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
- df.loc[self.df_new_var.index,self.df_new_var.columns] = df.loc[ self.df_new_var.index,self.df_new_var.columns] + self.df_new_var
104
- pass
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
- def reset(self,g):
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