OpenFisca-Core-test 46.0.0__py3-none-any.whl

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 (237) hide show
  1. openfisca_core/__init__.py +0 -0
  2. openfisca_core/commons/__init__.py +18 -0
  3. openfisca_core/commons/dummy.py +25 -0
  4. openfisca_core/commons/formulas.py +121 -0
  5. openfisca_core/commons/misc.py +109 -0
  6. openfisca_core/commons/py.typed +0 -0
  7. openfisca_core/commons/rates.py +114 -0
  8. openfisca_core/commons/tests/__init__.py +0 -0
  9. openfisca_core/commons/tests/test_dummy.py +9 -0
  10. openfisca_core/commons/tests/test_formulas.py +75 -0
  11. openfisca_core/commons/tests/test_rates.py +26 -0
  12. openfisca_core/data_storage/__init__.py +7 -0
  13. openfisca_core/data_storage/in_memory_storage.py +198 -0
  14. openfisca_core/data_storage/on_disk_storage.py +307 -0
  15. openfisca_core/data_storage/types.py +14 -0
  16. openfisca_core/entities/__init__.py +23 -0
  17. openfisca_core/entities/_core_entity.py +217 -0
  18. openfisca_core/entities/_description.py +55 -0
  19. openfisca_core/entities/entity.py +60 -0
  20. openfisca_core/entities/group_entity.py +123 -0
  21. openfisca_core/entities/helpers.py +165 -0
  22. openfisca_core/entities/py.typed +0 -0
  23. openfisca_core/entities/role.py +92 -0
  24. openfisca_core/entities/tests/__init__.py +0 -0
  25. openfisca_core/entities/tests/test_entity.py +10 -0
  26. openfisca_core/entities/tests/test_group_entity.py +70 -0
  27. openfisca_core/entities/tests/test_role.py +11 -0
  28. openfisca_core/entities/types.py +44 -0
  29. openfisca_core/errors/__init__.py +64 -0
  30. openfisca_core/errors/cycle_error.py +2 -0
  31. openfisca_core/errors/empty_argument_error.py +39 -0
  32. openfisca_core/errors/nan_creation_error.py +2 -0
  33. openfisca_core/errors/parameter_not_found_error.py +16 -0
  34. openfisca_core/errors/parameter_parsing_error.py +18 -0
  35. openfisca_core/errors/period_mismatch_error.py +9 -0
  36. openfisca_core/errors/situation_parsing_error.py +26 -0
  37. openfisca_core/errors/spiral_error.py +2 -0
  38. openfisca_core/errors/variable_name_config_error.py +2 -0
  39. openfisca_core/errors/variable_not_found_error.py +29 -0
  40. openfisca_core/experimental/__init__.py +9 -0
  41. openfisca_core/experimental/_errors.py +5 -0
  42. openfisca_core/experimental/_memory_config.py +41 -0
  43. openfisca_core/formula_helpers.py +9 -0
  44. openfisca_core/holders/__init__.py +33 -0
  45. openfisca_core/holders/helpers.py +93 -0
  46. openfisca_core/holders/holder.py +328 -0
  47. openfisca_core/holders/tests/__init__.py +0 -0
  48. openfisca_core/holders/tests/test_helpers.py +134 -0
  49. openfisca_core/holders/types.py +3 -0
  50. openfisca_core/indexed_enums/__init__.py +18 -0
  51. openfisca_core/indexed_enums/_enum_type.py +79 -0
  52. openfisca_core/indexed_enums/_errors.py +35 -0
  53. openfisca_core/indexed_enums/_guards.py +209 -0
  54. openfisca_core/indexed_enums/_utils.py +180 -0
  55. openfisca_core/indexed_enums/config.py +6 -0
  56. openfisca_core/indexed_enums/enum.py +218 -0
  57. openfisca_core/indexed_enums/enum_array.py +316 -0
  58. openfisca_core/indexed_enums/py.typed +0 -0
  59. openfisca_core/indexed_enums/tests/__init__.py +0 -0
  60. openfisca_core/indexed_enums/tests/test_enum.py +135 -0
  61. openfisca_core/indexed_enums/tests/test_enum_array.py +30 -0
  62. openfisca_core/indexed_enums/types.py +49 -0
  63. openfisca_core/memory_config.py +9 -0
  64. openfisca_core/model_api.py +71 -0
  65. openfisca_core/parameters/__init__.py +71 -0
  66. openfisca_core/parameters/at_instant_like.py +17 -0
  67. openfisca_core/parameters/config.py +55 -0
  68. openfisca_core/parameters/helpers.py +106 -0
  69. openfisca_core/parameters/parameter.py +217 -0
  70. openfisca_core/parameters/parameter_at_instant.py +75 -0
  71. openfisca_core/parameters/parameter_node.py +176 -0
  72. openfisca_core/parameters/parameter_node_at_instant.py +57 -0
  73. openfisca_core/parameters/parameter_scale.py +121 -0
  74. openfisca_core/parameters/parameter_scale_bracket.py +7 -0
  75. openfisca_core/parameters/values_history.py +5 -0
  76. openfisca_core/parameters/vectorial_parameter_node_at_instant.py +179 -0
  77. openfisca_core/periods/__init__.py +77 -0
  78. openfisca_core/periods/_errors.py +28 -0
  79. openfisca_core/periods/_parsers.py +122 -0
  80. openfisca_core/periods/config.py +20 -0
  81. openfisca_core/periods/date_unit.py +110 -0
  82. openfisca_core/periods/helpers.py +314 -0
  83. openfisca_core/periods/instant_.py +226 -0
  84. openfisca_core/periods/period_.py +919 -0
  85. openfisca_core/periods/py.typed +0 -0
  86. openfisca_core/periods/tests/__init__.py +0 -0
  87. openfisca_core/periods/tests/helpers/__init__.py +0 -0
  88. openfisca_core/periods/tests/helpers/test_helpers.py +65 -0
  89. openfisca_core/periods/tests/helpers/test_instant.py +73 -0
  90. openfisca_core/periods/tests/helpers/test_period.py +134 -0
  91. openfisca_core/periods/tests/test_instant.py +32 -0
  92. openfisca_core/periods/tests/test_parsers.py +129 -0
  93. openfisca_core/periods/tests/test_period.py +283 -0
  94. openfisca_core/populations/__init__.py +64 -0
  95. openfisca_core/populations/_core_population.py +454 -0
  96. openfisca_core/populations/_errors.py +65 -0
  97. openfisca_core/populations/group_population.py +326 -0
  98. openfisca_core/populations/population.py +142 -0
  99. openfisca_core/populations/tests/__init__.py +0 -0
  100. openfisca_core/populations/tests/test_members_position.py +116 -0
  101. openfisca_core/populations/types.py +110 -0
  102. openfisca_core/projectors/__init__.py +39 -0
  103. openfisca_core/projectors/entity_to_person_projector.py +12 -0
  104. openfisca_core/projectors/first_person_to_entity_projector.py +13 -0
  105. openfisca_core/projectors/helpers.py +139 -0
  106. openfisca_core/projectors/projector.py +38 -0
  107. openfisca_core/projectors/typing.py +27 -0
  108. openfisca_core/projectors/unique_role_to_entity_projector.py +14 -0
  109. openfisca_core/rates.py +9 -0
  110. openfisca_core/reforms/__init__.py +24 -0
  111. openfisca_core/reforms/in_yaml_test_reform.py +28 -0
  112. openfisca_core/reforms/reform.py +86 -0
  113. openfisca_core/scripts/__init__.py +106 -0
  114. openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.3.3.pyc +0 -0
  115. openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.4.2.pyc +0 -0
  116. openfisca_core/scripts/__pycache__/__init__.cpython-310.pyc +0 -0
  117. openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.3.3.pyc +0 -0
  118. openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.4.2.pyc +0 -0
  119. openfisca_core/scripts/__pycache__/__init__.cpython-311.pyc +0 -0
  120. openfisca_core/scripts/__pycache__/__init__.cpython-312-pytest-8.4.2.pyc +0 -0
  121. openfisca_core/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
  122. openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.3.3.pyc +0 -0
  123. openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.4.2.pyc +0 -0
  124. openfisca_core/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
  125. openfisca_core/scripts/__pycache__/find_placeholders.cpython-311.pyc +0 -0
  126. openfisca_core/scripts/__pycache__/find_placeholders.cpython-313.pyc +0 -0
  127. openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-311.pyc +0 -0
  128. openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-313.pyc +0 -0
  129. openfisca_core/scripts/__pycache__/measure_performances.cpython-311.pyc +0 -0
  130. openfisca_core/scripts/__pycache__/measure_performances.cpython-313.pyc +0 -0
  131. openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-311.pyc +0 -0
  132. openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-313.pyc +0 -0
  133. openfisca_core/scripts/__pycache__/openfisca_command.cpython-310.pyc +0 -0
  134. openfisca_core/scripts/__pycache__/openfisca_command.cpython-311.pyc +0 -0
  135. openfisca_core/scripts/__pycache__/openfisca_command.cpython-312.pyc +0 -0
  136. openfisca_core/scripts/__pycache__/openfisca_command.cpython-313.pyc +0 -0
  137. openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-311.pyc +0 -0
  138. openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-313.pyc +0 -0
  139. openfisca_core/scripts/__pycache__/run_test.cpython-310.pyc +0 -0
  140. openfisca_core/scripts/__pycache__/run_test.cpython-311.pyc +0 -0
  141. openfisca_core/scripts/__pycache__/run_test.cpython-312.pyc +0 -0
  142. openfisca_core/scripts/__pycache__/run_test.cpython-313.pyc +0 -0
  143. openfisca_core/scripts/__pycache__/simulation_generator.cpython-311.pyc +0 -0
  144. openfisca_core/scripts/__pycache__/simulation_generator.cpython-313.pyc +0 -0
  145. openfisca_core/scripts/assets/__init__.py +0 -0
  146. openfisca_core/scripts/assets/__pycache__/__init__.cpython-311.pyc +0 -0
  147. openfisca_core/scripts/assets/__pycache__/__init__.cpython-313.pyc +0 -0
  148. openfisca_core/scripts/assets/index.html +140 -0
  149. openfisca_core/scripts/find_placeholders.py +51 -0
  150. openfisca_core/scripts/measure_numpy_condition_notations.py +137 -0
  151. openfisca_core/scripts/measure_performances.py +291 -0
  152. openfisca_core/scripts/measure_performances_fancy_indexing.py +89 -0
  153. openfisca_core/scripts/migrations/__init__.py +0 -0
  154. openfisca_core/scripts/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
  155. openfisca_core/scripts/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
  156. openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-311.pyc +0 -0
  157. openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-313.pyc +0 -0
  158. openfisca_core/scripts/migrations/v16_2_to_v17/__init__.py +0 -0
  159. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-311.pyc +0 -0
  160. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-313.pyc +0 -0
  161. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-311.pyc +0 -0
  162. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-313.pyc +0 -0
  163. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-311.pyc +0 -0
  164. openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-313.pyc +0 -0
  165. openfisca_core/scripts/migrations/v16_2_to_v17/legislation.xsd +102 -0
  166. openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_country_template.py +30 -0
  167. openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_extension_template.py +26 -0
  168. openfisca_core/scripts/migrations/v24_to_25.py +156 -0
  169. openfisca_core/scripts/openfisca_command.py +192 -0
  170. openfisca_core/scripts/remove_fuzzy.py +213 -0
  171. openfisca_core/scripts/run_test.py +51 -0
  172. openfisca_core/scripts/simulation_generator.py +90 -0
  173. openfisca_core/simulation_builder.py +16 -0
  174. openfisca_core/simulations/__init__.py +45 -0
  175. openfisca_core/simulations/_build_default_simulation.py +158 -0
  176. openfisca_core/simulations/_build_from_variables.py +230 -0
  177. openfisca_core/simulations/_type_guards.py +298 -0
  178. openfisca_core/simulations/helpers.py +111 -0
  179. openfisca_core/simulations/simulation.py +618 -0
  180. openfisca_core/simulations/simulation_builder.py +855 -0
  181. openfisca_core/simulations/typing.py +203 -0
  182. openfisca_core/taxbenefitsystems/__init__.py +26 -0
  183. openfisca_core/taxbenefitsystems/tax_benefit_system.py +584 -0
  184. openfisca_core/taxscales/__init__.py +35 -0
  185. openfisca_core/taxscales/abstract_rate_tax_scale.py +41 -0
  186. openfisca_core/taxscales/abstract_tax_scale.py +53 -0
  187. openfisca_core/taxscales/amount_tax_scale_like.py +55 -0
  188. openfisca_core/taxscales/helpers.py +44 -0
  189. openfisca_core/taxscales/linear_average_rate_tax_scale.py +76 -0
  190. openfisca_core/taxscales/marginal_amount_tax_scale.py +34 -0
  191. openfisca_core/taxscales/marginal_rate_tax_scale.py +286 -0
  192. openfisca_core/taxscales/rate_tax_scale_like.py +214 -0
  193. openfisca_core/taxscales/single_amount_tax_scale.py +32 -0
  194. openfisca_core/taxscales/tax_scale_like.py +65 -0
  195. openfisca_core/tools/__init__.py +94 -0
  196. openfisca_core/tools/parallel_plugin.py +55 -0
  197. openfisca_core/tools/simulation_dumper.py +137 -0
  198. openfisca_core/tools/test_runner.py +802 -0
  199. openfisca_core/tracers/__init__.py +40 -0
  200. openfisca_core/tracers/computation_log.py +196 -0
  201. openfisca_core/tracers/flat_trace.py +87 -0
  202. openfisca_core/tracers/full_tracer.py +172 -0
  203. openfisca_core/tracers/performance_log.py +133 -0
  204. openfisca_core/tracers/simple_tracer.py +64 -0
  205. openfisca_core/tracers/trace_node.py +121 -0
  206. openfisca_core/tracers/tracing_parameter_node_at_instant.py +81 -0
  207. openfisca_core/types.py +548 -0
  208. openfisca_core/variables/__init__.py +26 -0
  209. openfisca_core/variables/config.py +53 -0
  210. openfisca_core/variables/helpers.py +67 -0
  211. openfisca_core/variables/tests/__init__.py +0 -0
  212. openfisca_core/variables/tests/test_definition_period.py +43 -0
  213. openfisca_core/variables/variable.py +474 -0
  214. openfisca_core/warnings/__init__.py +25 -0
  215. openfisca_core/warnings/libyaml_warning.py +2 -0
  216. openfisca_core/warnings/tempfile_warning.py +2 -0
  217. openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/CHANGELOG.md +4209 -0
  218. openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/README.md +152 -0
  219. openfisca_core_test-46.0.0.dist-info/METADATA +194 -0
  220. openfisca_core_test-46.0.0.dist-info/RECORD +237 -0
  221. openfisca_core_test-46.0.0.dist-info/WHEEL +5 -0
  222. openfisca_core_test-46.0.0.dist-info/entry_points.txt +3 -0
  223. openfisca_core_test-46.0.0.dist-info/licenses/LICENSE +661 -0
  224. openfisca_core_test-46.0.0.dist-info/top_level.txt +2 -0
  225. openfisca_web_api/__init__.py +0 -0
  226. openfisca_web_api/app.py +226 -0
  227. openfisca_web_api/errors.py +11 -0
  228. openfisca_web_api/handlers.py +90 -0
  229. openfisca_web_api/loader/__init__.py +22 -0
  230. openfisca_web_api/loader/entities.py +28 -0
  231. openfisca_web_api/loader/parameters.py +122 -0
  232. openfisca_web_api/loader/spec.py +168 -0
  233. openfisca_web_api/loader/tax_benefit_system.py +27 -0
  234. openfisca_web_api/loader/variables.py +121 -0
  235. openfisca_web_api/openAPI.yml +434 -0
  236. openfisca_web_api/scripts/__init__.py +0 -0
  237. openfisca_web_api/scripts/serve.py +99 -0
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env python
2
+ # remove_fuzzy.py : Remove the fuzzy attribute in xml files and add END tags.
3
+ # See https://github.com/openfisca/openfisca-core/issues/437
4
+
5
+ import datetime
6
+ import re
7
+ import sys
8
+
9
+ import numpy
10
+
11
+ assert len(sys.argv) == 2
12
+ filename = sys.argv[1]
13
+
14
+ with open(filename) as f:
15
+ lines = f.readlines()
16
+
17
+
18
+ # Remove fuzzy
19
+
20
+ lines_2 = [line.replace(' fuzzy="true"', "") for line in lines]
21
+
22
+ regex_indent = r"^(\s*)<VALUE "
23
+ regex_fin = r' fin="([0-9\-]+)"'
24
+ regex_iso8601 = r"([0-9]+)-([0-9]+)-([0-9]+)"
25
+ one_day = datetime.timedelta(days=1)
26
+
27
+ lines_3 = []
28
+ for line in lines_2:
29
+ if ' fin="' in line:
30
+ m_indent = re.search(regex_indent, line)
31
+ spaces = m_indent.groups()[0]
32
+
33
+ m_fin = re.search(regex_fin, line)
34
+ fin_date = m_fin.groups()[0]
35
+ fin_left, fin_right = m_fin.span()
36
+
37
+ m_date = re.match(regex_iso8601, fin_date)
38
+ year_str, month_str, day_str = m_date.groups()
39
+ date_parsed = datetime.date(int(year_str), int(month_str), int(day_str))
40
+ date_parsed += one_day
41
+ fin_date = date_parsed.isoformat()
42
+
43
+ lines_3.append(spaces + '<END deb="' + fin_date + '" />\n')
44
+ lines_3.append(line[:fin_left] + line[fin_right:])
45
+ else:
46
+ lines_3.append(line)
47
+
48
+
49
+ # Remove useless END tags
50
+
51
+ regex_code = "<(CODE|SEUIL|TAUX|ASSIETTE)"
52
+ regex_code_end = "</(CODE|SEUIL|TAUX|ASSIETTE)"
53
+ regex_value = "<VALUE"
54
+ regex_end = "<END"
55
+
56
+ bool_code = [bool(re.search(regex_code, line)) for line in lines_3]
57
+
58
+ bool_code_end = [bool(re.search(regex_code_end, line)) for line in lines_3]
59
+
60
+ bool_value = [bool(re.search(regex_value, line)) for line in lines_3]
61
+
62
+ bool_end = [bool(re.search(regex_end, line)) for line in lines_3]
63
+
64
+
65
+ index_code = [i + 1 for i, x in enumerate(bool_code) if x]
66
+ index_code_end = [i for i, x in enumerate(bool_code_end) if x]
67
+
68
+ assert len(index_code) == len(index_code_end)
69
+
70
+ position_code = list(zip(index_code, index_code_end))
71
+
72
+
73
+ end_to_remove = []
74
+ regex_deb = r' deb="([0-9\-]+)"'
75
+
76
+ for code_begining, code_end in position_code:
77
+ deb_list = []
78
+
79
+ for local_i, line in enumerate(lines_3[code_begining:code_end]):
80
+ i = local_i + code_begining
81
+
82
+ m_deb = re.search(regex_deb, line)
83
+ if m_deb:
84
+ deb_tmp = m_deb.groups()[0]
85
+ deb_list.append(deb_tmp)
86
+ else:
87
+ deb_list.append(None)
88
+
89
+ for repr_deb in set(deb_list) - {None}:
90
+ part_list = [
91
+ local_i + code_begining
92
+ for local_i, deb in enumerate(deb_list)
93
+ if deb == repr_deb
94
+ ]
95
+
96
+ assert len(part_list) <= 2
97
+
98
+ if len(part_list) == 2:
99
+ i1 = part_list[0]
100
+ i2 = part_list[1]
101
+ if bool_value[i1]:
102
+ assert not bool_value[i2]
103
+ assert not bool_end[i1]
104
+ assert bool_end[i2]
105
+ i_value = i1
106
+ i_end = i2
107
+ else:
108
+ assert bool_value[i2]
109
+ assert bool_end[i1]
110
+ assert not bool_end[i2]
111
+ i_value = i2
112
+ i_end = i1
113
+
114
+ end_to_remove.append(i_end)
115
+
116
+
117
+ end_to_remove_set = set(end_to_remove)
118
+
119
+
120
+ lines_4 = [line for j, line in enumerate(lines_3) if j not in end_to_remove_set]
121
+
122
+ # Order by "deb"
123
+
124
+ bool_code = [bool(re.search(regex_code, line)) for line in lines_4]
125
+
126
+ bool_code_end = [bool(re.search(regex_code_end, line)) for line in lines_4]
127
+
128
+
129
+ index_code = [j + 1 for j, x in enumerate(bool_code) if x]
130
+ index_code_end = [j for j, x in enumerate(bool_code_end) if x]
131
+
132
+ assert len(index_code) == len(index_code_end)
133
+
134
+ position_code = list(zip(index_code, index_code_end))
135
+
136
+ i = 0
137
+ lines_5 = []
138
+ for code_begining, code_end in position_code:
139
+ while i < code_begining:
140
+ lines_5.append(lines_4[i])
141
+ i += 1
142
+
143
+ comment_list = []
144
+ deb_list = []
145
+
146
+ for local_i, line in enumerate(lines_4[code_begining:code_end]):
147
+ i = local_i + code_begining
148
+
149
+ m_deb = re.search(regex_deb, line)
150
+ if m_deb:
151
+ deb_tmp = m_deb.groups()[0]
152
+ deb_list.append(deb_tmp)
153
+ else:
154
+ comment_list.append(local_i)
155
+ deb_list.append("z")
156
+
157
+ lines_5 += [lines_4[local_i + code_begining] for local_i in comment_list]
158
+
159
+ order = numpy.argsort(deb_list)[::-1]
160
+ lines_5 += [
161
+ lines_4[local_i + code_begining]
162
+ for local_i in order
163
+ if deb_list[local_i] != "z"
164
+ ]
165
+
166
+ i += 1
167
+ while i < len(lines_4):
168
+ lines_5.append(lines_4[i])
169
+ i += 1
170
+
171
+
172
+ # Remove duplicate values
173
+
174
+ regex_value2 = r'^(?: )*<VALUE deb="\d{4}-\d{2}-\d{2}" valeur="((?:\d|.)+)" \/>\n$'
175
+
176
+ bool_code = [bool(re.search(regex_code, line)) for line in lines_5]
177
+
178
+ bool_code_end = [bool(re.search(regex_code_end, line)) for line in lines_5]
179
+
180
+ list_value = []
181
+ for line in lines_5:
182
+ m = re.match(regex_value2, line)
183
+ if m:
184
+ list_value.append(m.groups()[0])
185
+ else:
186
+ list_value.append(None)
187
+
188
+
189
+ index_code = [j + 1 for j, x in enumerate(bool_code) if x]
190
+ index_code_end = [j for j, x in enumerate(bool_code_end) if x]
191
+
192
+ assert len(index_code) == len(index_code_end)
193
+
194
+ position_code = list(zip(index_code, index_code_end))
195
+
196
+ to_remove = []
197
+ for i in range(len(lines_5) - 1):
198
+ if (
199
+ (list_value[i] is not None)
200
+ and (list_value[i + 1] is not None)
201
+ and (list_value[i] == list_value[i + 1])
202
+ ):
203
+ to_remove.append(i)
204
+
205
+ to_remove_set = set(to_remove)
206
+
207
+ lines_6 = [line for j, line in enumerate(lines_5) if j not in to_remove_set]
208
+
209
+ # Write
210
+
211
+ with open(filename, "w") as f:
212
+ for line in lines_6:
213
+ f.write(line)
@@ -0,0 +1,51 @@
1
+ import logging
2
+ import os
3
+ import sys
4
+
5
+ from openfisca_core.scripts import build_tax_benefit_system
6
+ from openfisca_core.tools.test_runner import run_tests
7
+
8
+
9
+ def main(parser) -> None:
10
+ args = parser.parse_args()
11
+ logging.basicConfig(
12
+ level=logging.DEBUG if args.verbose else logging.WARNING,
13
+ stream=sys.stdout,
14
+ )
15
+
16
+ tax_benefit_system = build_tax_benefit_system(
17
+ args.country_package,
18
+ args.extensions,
19
+ args.reforms,
20
+ )
21
+
22
+ options = {
23
+ "country_package": args.country_package,
24
+ "extensions": args.extensions,
25
+ "reforms": args.reforms,
26
+ "pdb": args.pdb,
27
+ "performance_graph": args.performance_graph,
28
+ "performance_tables": args.performance_tables,
29
+ "verbose": args.verbose,
30
+ "aggregate": args.aggregate,
31
+ "max_depth": args.max_depth,
32
+ "name_filter": args.name_filter,
33
+ "only_variables": args.only_variables,
34
+ "ignore_variables": args.ignore_variables,
35
+ "ignore_default": args.ignore_default,
36
+ }
37
+
38
+ paths = [os.path.abspath(path) for path in args.path]
39
+
40
+ # Parallel mode
41
+ if args.in_parallel:
42
+ from openfisca_core.tools.test_runner import run_tests_in_parallel
43
+
44
+ return sys.exit(
45
+ run_tests_in_parallel(
46
+ tax_benefit_system, paths, options, args.num_workers, args.verbose
47
+ )
48
+ )
49
+
50
+ # Default serial mode
51
+ sys.exit(run_tests(tax_benefit_system, paths, options))
@@ -0,0 +1,90 @@
1
+ import random
2
+
3
+ import numpy
4
+
5
+ from openfisca_core.simulations import Simulation
6
+
7
+
8
+ def make_simulation(tax_benefit_system, nb_persons, nb_groups, **kwargs):
9
+ """Generate a simulation containing nb_persons persons spread in nb_groups groups.
10
+
11
+ Example:
12
+ >>> from openfisca_core.scripts.simulation_generator import make_simulation
13
+ >>> from openfisca_france import CountryTaxBenefitSystem
14
+ >>> tbs = CountryTaxBenefitSystem()
15
+ >>> simulation = make_simulation(
16
+ ... tbs, 400, 100
17
+ ... ) # Create a simulation with 400 persons, spread among 100 families
18
+ >>> simulation.calculate("revenu_disponible", 2017)
19
+
20
+ """
21
+ simulation = Simulation(tax_benefit_system=tax_benefit_system, **kwargs)
22
+ simulation.persons.ids = numpy.arange(nb_persons)
23
+ simulation.persons.count = nb_persons
24
+ adults = [0, *sorted(random.sample(range(1, nb_persons), nb_groups - 1))]
25
+
26
+ members_entity_id = numpy.empty(nb_persons, dtype=int)
27
+
28
+ # A legacy role is an index that every person within an entity has. For instance, the 'demandeur' has legacy role 0, the 'conjoint' 1, the first 'child' 2, the second 3, etc.
29
+ members_legacy_role = numpy.empty(nb_persons, dtype=int)
30
+
31
+ id_group = -1
32
+ for id_person in range(nb_persons):
33
+ if id_person in adults:
34
+ id_group += 1
35
+ legacy_role = 0
36
+ else:
37
+ legacy_role = 2 if legacy_role == 0 else legacy_role + 1
38
+ members_legacy_role[id_person] = legacy_role
39
+ members_entity_id[id_person] = id_group
40
+
41
+ for entity in simulation.populations.values():
42
+ if not entity.is_person:
43
+ entity.members_entity_id = members_entity_id
44
+ entity.count = nb_groups
45
+ entity.members_role = numpy.where(
46
+ members_legacy_role == 0,
47
+ entity.flattened_roles[0],
48
+ entity.flattened_roles[-1],
49
+ )
50
+ return simulation
51
+
52
+
53
+ def randomly_init_variable(
54
+ simulation,
55
+ variable_name: str,
56
+ period,
57
+ max_value,
58
+ condition=None,
59
+ ) -> None:
60
+ """Initialise a variable with random values (from 0 to max_value) for the given period.
61
+ If a condition vector is provided, only set the value of persons or groups for which condition is True.
62
+
63
+ Example:
64
+ >>> from openfisca_core.scripts.simulation_generator import (
65
+ ... make_simulation,
66
+ ... randomly_init_variable,
67
+ ... )
68
+ >>> from openfisca_france import CountryTaxBenefitSystem
69
+ >>> tbs = CountryTaxBenefitSystem()
70
+ >>> simulation = make_simulation(
71
+ ... tbs, 400, 100
72
+ ... ) # Create a simulation with 400 persons, spread among 100 families
73
+ >>> randomly_init_variable(
74
+ ... simulation,
75
+ ... "salaire_net",
76
+ ... 2017,
77
+ ... max_value=50000,
78
+ ... condition=simulation.persons.has_role(simulation.famille.DEMANDEUR),
79
+ ... ) # Randomly set a salaire_net for all persons between 0 and 50000?
80
+ >>> simulation.calculate("revenu_disponible", 2017)
81
+
82
+ """
83
+ if condition is None:
84
+ condition = True
85
+ variable = simulation.tax_benefit_system.get_variable(variable_name)
86
+ population = simulation.get_variable_population(variable_name)
87
+ value = (numpy.random.rand(population.count) * max_value * condition).astype(
88
+ variable.dtype,
89
+ )
90
+ simulation.set_input(variable_name, period, value)
@@ -0,0 +1,16 @@
1
+ # The simulation builder module has been deprecated since X.X.X,
2
+ # and will be removed in the future.
3
+ #
4
+ # Module's contents have been moved to the simulation module.
5
+ #
6
+ # The following are transitional imports to ensure non-breaking changes.
7
+ # Could be deprecated in the next major release.
8
+
9
+ from openfisca_core.simulations import ( # noqa: F401
10
+ Simulation,
11
+ SimulationBuilder,
12
+ calculate_output_add,
13
+ calculate_output_divide,
14
+ check_type,
15
+ transform_to_strict_syntax,
16
+ )
@@ -0,0 +1,45 @@
1
+ # Transitional imports to ensure non-breaking changes.
2
+ # Could be deprecated in the next major release.
3
+ #
4
+ # How imports are being used today:
5
+ #
6
+ # >>> from openfisca_core.module import symbol
7
+ #
8
+ # The previous example provokes cyclic dependency problems
9
+ # that prevent us from modularizing the different components
10
+ # of the library so to make them easier to test and to maintain.
11
+ #
12
+ # How could them be used after the next major release:
13
+ #
14
+ # >>> from openfisca_core import module
15
+ # >>> module.symbol()
16
+ #
17
+ # And for classes:
18
+ #
19
+ # >>> from openfisca_core.module import Symbol
20
+ # >>> Symbol()
21
+ #
22
+ # See: https://www.python.org/dev/peps/pep-0008/#imports
23
+
24
+ from openfisca_core.errors import CycleError, NaNCreationError, SpiralError
25
+
26
+ from .helpers import (
27
+ calculate_output_add,
28
+ calculate_output_divide,
29
+ check_type,
30
+ transform_to_strict_syntax,
31
+ )
32
+ from .simulation import Simulation
33
+ from .simulation_builder import SimulationBuilder
34
+
35
+ __all__ = [
36
+ "CycleError",
37
+ "NaNCreationError",
38
+ "Simulation",
39
+ "SimulationBuilder",
40
+ "SpiralError",
41
+ "calculate_output_add",
42
+ "calculate_output_divide",
43
+ "check_type",
44
+ "transform_to_strict_syntax",
45
+ ]
@@ -0,0 +1,158 @@
1
+ """This module contains the _BuildDefaultSimulation class."""
2
+
3
+ from typing import Self
4
+
5
+ import numpy
6
+
7
+ from .simulation import Simulation
8
+ from .typing import Entity, Population, TaxBenefitSystem
9
+
10
+
11
+ class _BuildDefaultSimulation:
12
+ """Build a default simulation.
13
+
14
+ Args:
15
+ tax_benefit_system(TaxBenefitSystem): The tax-benefit system.
16
+ count(int): The number of periods.
17
+
18
+ Examples:
19
+ >>> from openfisca_core import entities, taxbenefitsystems
20
+
21
+ >>> role = {"key": "stray", "plural": "stray", "label": "", "doc": ""}
22
+ >>> single_entity = entities.Entity("dog", "dogs", "", "")
23
+ >>> group_entity = entities.GroupEntity("pack", "packs", "", "", [role])
24
+ >>> test_entities = [single_entity, group_entity]
25
+ >>> tax_benefit_system = taxbenefitsystems.TaxBenefitSystem(test_entities)
26
+ >>> count = 1
27
+ >>> builder = (
28
+ ... _BuildDefaultSimulation(tax_benefit_system, count)
29
+ ... .add_count()
30
+ ... .add_ids()
31
+ ... .add_members_entity_id()
32
+ ... )
33
+
34
+ >>> builder.count
35
+ 1
36
+
37
+ >>> sorted(builder.populations.keys())
38
+ ['dog', 'pack']
39
+
40
+ >>> sorted(builder.simulation.populations.keys())
41
+ ['dog', 'pack']
42
+
43
+ """
44
+
45
+ #: The number of Population.
46
+ count: int
47
+
48
+ #: The built populations.
49
+ populations: dict[str, Population[Entity]]
50
+
51
+ #: The built simulation.
52
+ simulation: Simulation
53
+
54
+ def __init__(self, tax_benefit_system: TaxBenefitSystem, count: int) -> None:
55
+ self.count = count
56
+ self.populations = tax_benefit_system.instantiate_entities()
57
+ self.simulation = Simulation(tax_benefit_system, self.populations)
58
+
59
+ def add_count(self) -> Self:
60
+ """Add the number of Population to the simulation.
61
+
62
+ Returns:
63
+ _BuildDefaultSimulation: The builder.
64
+
65
+ Examples:
66
+ >>> from openfisca_core import entities, taxbenefitsystems
67
+
68
+ >>> role = {"key": "stray", "plural": "stray", "label": "", "doc": ""}
69
+ >>> single_entity = entities.Entity("dog", "dogs", "", "")
70
+ >>> group_entity = entities.GroupEntity("pack", "packs", "", "", [role])
71
+ >>> test_entities = [single_entity, group_entity]
72
+ >>> tax_benefit_system = taxbenefitsystems.TaxBenefitSystem(test_entities)
73
+ >>> count = 2
74
+ >>> builder = _BuildDefaultSimulation(tax_benefit_system, count)
75
+
76
+ >>> builder.add_count()
77
+ <..._BuildDefaultSimulation object at ...>
78
+
79
+ >>> builder.populations["dog"].count
80
+ 2
81
+
82
+ >>> builder.populations["pack"].count
83
+ 2
84
+
85
+ """
86
+ for population in self.populations.values():
87
+ population.count = self.count
88
+
89
+ return self
90
+
91
+ def add_ids(self) -> Self:
92
+ """Add the populations ids to the simulation.
93
+
94
+ Returns:
95
+ _BuildDefaultSimulation: The builder.
96
+
97
+ Examples:
98
+ >>> from openfisca_core import entities, taxbenefitsystems
99
+
100
+ >>> role = {"key": "stray", "plural": "stray", "label": "", "doc": ""}
101
+ >>> single_entity = entities.Entity("dog", "dogs", "", "")
102
+ >>> group_entity = entities.GroupEntity("pack", "packs", "", "", [role])
103
+ >>> test_entities = [single_entity, group_entity]
104
+ >>> tax_benefit_system = taxbenefitsystems.TaxBenefitSystem(test_entities)
105
+ >>> count = 2
106
+ >>> builder = _BuildDefaultSimulation(tax_benefit_system, count)
107
+
108
+ >>> builder.add_ids()
109
+ <..._BuildDefaultSimulation object at ...>
110
+
111
+ >>> builder.populations["dog"].ids
112
+ array([0, 1])
113
+
114
+ >>> builder.populations["pack"].ids
115
+ array([0, 1])
116
+
117
+ """
118
+ for population in self.populations.values():
119
+ population.ids = numpy.array(range(self.count))
120
+
121
+ return self
122
+
123
+ def add_members_entity_id(self) -> Self:
124
+ """Add ???
125
+
126
+ Each SingleEntity has its own GroupEntity.
127
+
128
+ Returns:
129
+ _BuildDefaultSimulation: The builder.
130
+
131
+ Examples:
132
+ >>> from openfisca_core import entities, taxbenefitsystems
133
+
134
+ >>> role = {"key": "stray", "plural": "stray", "label": "", "doc": ""}
135
+ >>> single_entity = entities.Entity("dog", "dogs", "", "")
136
+ >>> group_entity = entities.GroupEntity("pack", "packs", "", "", [role])
137
+ >>> test_entities = [single_entity, group_entity]
138
+ >>> tax_benefit_system = taxbenefitsystems.TaxBenefitSystem(test_entities)
139
+ >>> count = 2
140
+ >>> builder = _BuildDefaultSimulation(tax_benefit_system, count)
141
+
142
+ >>> builder.add_members_entity_id()
143
+ <..._BuildDefaultSimulation object at ...>
144
+
145
+ >>> population = builder.populations["pack"]
146
+
147
+ >>> hasattr(population, "members_entity_id")
148
+ True
149
+
150
+ >>> population.members_entity_id
151
+ array([0, 1])
152
+
153
+ """
154
+ for population in self.populations.values():
155
+ if hasattr(population, "members_entity_id"):
156
+ population.members_entity_id = numpy.array(range(self.count))
157
+
158
+ return self