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.
- openfisca_core/__init__.py +0 -0
- openfisca_core/commons/__init__.py +18 -0
- openfisca_core/commons/dummy.py +25 -0
- openfisca_core/commons/formulas.py +121 -0
- openfisca_core/commons/misc.py +109 -0
- openfisca_core/commons/py.typed +0 -0
- openfisca_core/commons/rates.py +114 -0
- openfisca_core/commons/tests/__init__.py +0 -0
- openfisca_core/commons/tests/test_dummy.py +9 -0
- openfisca_core/commons/tests/test_formulas.py +75 -0
- openfisca_core/commons/tests/test_rates.py +26 -0
- openfisca_core/data_storage/__init__.py +7 -0
- openfisca_core/data_storage/in_memory_storage.py +198 -0
- openfisca_core/data_storage/on_disk_storage.py +307 -0
- openfisca_core/data_storage/types.py +14 -0
- openfisca_core/entities/__init__.py +23 -0
- openfisca_core/entities/_core_entity.py +217 -0
- openfisca_core/entities/_description.py +55 -0
- openfisca_core/entities/entity.py +60 -0
- openfisca_core/entities/group_entity.py +123 -0
- openfisca_core/entities/helpers.py +165 -0
- openfisca_core/entities/py.typed +0 -0
- openfisca_core/entities/role.py +92 -0
- openfisca_core/entities/tests/__init__.py +0 -0
- openfisca_core/entities/tests/test_entity.py +10 -0
- openfisca_core/entities/tests/test_group_entity.py +70 -0
- openfisca_core/entities/tests/test_role.py +11 -0
- openfisca_core/entities/types.py +44 -0
- openfisca_core/errors/__init__.py +64 -0
- openfisca_core/errors/cycle_error.py +2 -0
- openfisca_core/errors/empty_argument_error.py +39 -0
- openfisca_core/errors/nan_creation_error.py +2 -0
- openfisca_core/errors/parameter_not_found_error.py +16 -0
- openfisca_core/errors/parameter_parsing_error.py +18 -0
- openfisca_core/errors/period_mismatch_error.py +9 -0
- openfisca_core/errors/situation_parsing_error.py +26 -0
- openfisca_core/errors/spiral_error.py +2 -0
- openfisca_core/errors/variable_name_config_error.py +2 -0
- openfisca_core/errors/variable_not_found_error.py +29 -0
- openfisca_core/experimental/__init__.py +9 -0
- openfisca_core/experimental/_errors.py +5 -0
- openfisca_core/experimental/_memory_config.py +41 -0
- openfisca_core/formula_helpers.py +9 -0
- openfisca_core/holders/__init__.py +33 -0
- openfisca_core/holders/helpers.py +93 -0
- openfisca_core/holders/holder.py +328 -0
- openfisca_core/holders/tests/__init__.py +0 -0
- openfisca_core/holders/tests/test_helpers.py +134 -0
- openfisca_core/holders/types.py +3 -0
- openfisca_core/indexed_enums/__init__.py +18 -0
- openfisca_core/indexed_enums/_enum_type.py +79 -0
- openfisca_core/indexed_enums/_errors.py +35 -0
- openfisca_core/indexed_enums/_guards.py +209 -0
- openfisca_core/indexed_enums/_utils.py +180 -0
- openfisca_core/indexed_enums/config.py +6 -0
- openfisca_core/indexed_enums/enum.py +218 -0
- openfisca_core/indexed_enums/enum_array.py +316 -0
- openfisca_core/indexed_enums/py.typed +0 -0
- openfisca_core/indexed_enums/tests/__init__.py +0 -0
- openfisca_core/indexed_enums/tests/test_enum.py +135 -0
- openfisca_core/indexed_enums/tests/test_enum_array.py +30 -0
- openfisca_core/indexed_enums/types.py +49 -0
- openfisca_core/memory_config.py +9 -0
- openfisca_core/model_api.py +71 -0
- openfisca_core/parameters/__init__.py +71 -0
- openfisca_core/parameters/at_instant_like.py +17 -0
- openfisca_core/parameters/config.py +55 -0
- openfisca_core/parameters/helpers.py +106 -0
- openfisca_core/parameters/parameter.py +217 -0
- openfisca_core/parameters/parameter_at_instant.py +75 -0
- openfisca_core/parameters/parameter_node.py +176 -0
- openfisca_core/parameters/parameter_node_at_instant.py +57 -0
- openfisca_core/parameters/parameter_scale.py +121 -0
- openfisca_core/parameters/parameter_scale_bracket.py +7 -0
- openfisca_core/parameters/values_history.py +5 -0
- openfisca_core/parameters/vectorial_parameter_node_at_instant.py +179 -0
- openfisca_core/periods/__init__.py +77 -0
- openfisca_core/periods/_errors.py +28 -0
- openfisca_core/periods/_parsers.py +122 -0
- openfisca_core/periods/config.py +20 -0
- openfisca_core/periods/date_unit.py +110 -0
- openfisca_core/periods/helpers.py +314 -0
- openfisca_core/periods/instant_.py +226 -0
- openfisca_core/periods/period_.py +919 -0
- openfisca_core/periods/py.typed +0 -0
- openfisca_core/periods/tests/__init__.py +0 -0
- openfisca_core/periods/tests/helpers/__init__.py +0 -0
- openfisca_core/periods/tests/helpers/test_helpers.py +65 -0
- openfisca_core/periods/tests/helpers/test_instant.py +73 -0
- openfisca_core/periods/tests/helpers/test_period.py +134 -0
- openfisca_core/periods/tests/test_instant.py +32 -0
- openfisca_core/periods/tests/test_parsers.py +129 -0
- openfisca_core/periods/tests/test_period.py +283 -0
- openfisca_core/populations/__init__.py +64 -0
- openfisca_core/populations/_core_population.py +454 -0
- openfisca_core/populations/_errors.py +65 -0
- openfisca_core/populations/group_population.py +326 -0
- openfisca_core/populations/population.py +142 -0
- openfisca_core/populations/tests/__init__.py +0 -0
- openfisca_core/populations/tests/test_members_position.py +116 -0
- openfisca_core/populations/types.py +110 -0
- openfisca_core/projectors/__init__.py +39 -0
- openfisca_core/projectors/entity_to_person_projector.py +12 -0
- openfisca_core/projectors/first_person_to_entity_projector.py +13 -0
- openfisca_core/projectors/helpers.py +139 -0
- openfisca_core/projectors/projector.py +38 -0
- openfisca_core/projectors/typing.py +27 -0
- openfisca_core/projectors/unique_role_to_entity_projector.py +14 -0
- openfisca_core/rates.py +9 -0
- openfisca_core/reforms/__init__.py +24 -0
- openfisca_core/reforms/in_yaml_test_reform.py +28 -0
- openfisca_core/reforms/reform.py +86 -0
- openfisca_core/scripts/__init__.py +106 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-312-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.3.3.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313-pytest-8.4.2.pyc +0 -0
- openfisca_core/scripts/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/find_placeholders.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/find_placeholders.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_numpy_condition_notations.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/measure_performances_fancy_indexing.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/openfisca_command.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/remove_fuzzy.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-310.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-312.pyc +0 -0
- openfisca_core/scripts/__pycache__/run_test.cpython-313.pyc +0 -0
- openfisca_core/scripts/__pycache__/simulation_generator.cpython-311.pyc +0 -0
- openfisca_core/scripts/__pycache__/simulation_generator.cpython-313.pyc +0 -0
- openfisca_core/scripts/assets/__init__.py +0 -0
- openfisca_core/scripts/assets/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/assets/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/assets/index.html +140 -0
- openfisca_core/scripts/find_placeholders.py +51 -0
- openfisca_core/scripts/measure_numpy_condition_notations.py +137 -0
- openfisca_core/scripts/measure_performances.py +291 -0
- openfisca_core/scripts/measure_performances_fancy_indexing.py +89 -0
- openfisca_core/scripts/migrations/__init__.py +0 -0
- openfisca_core/scripts/migrations/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/__pycache__/v24_to_25.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__init__.py +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/__init__.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_country_template.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-311.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/__pycache__/xml_to_yaml_extension_template.cpython-313.pyc +0 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/legislation.xsd +102 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_country_template.py +30 -0
- openfisca_core/scripts/migrations/v16_2_to_v17/xml_to_yaml_extension_template.py +26 -0
- openfisca_core/scripts/migrations/v24_to_25.py +156 -0
- openfisca_core/scripts/openfisca_command.py +192 -0
- openfisca_core/scripts/remove_fuzzy.py +213 -0
- openfisca_core/scripts/run_test.py +51 -0
- openfisca_core/scripts/simulation_generator.py +90 -0
- openfisca_core/simulation_builder.py +16 -0
- openfisca_core/simulations/__init__.py +45 -0
- openfisca_core/simulations/_build_default_simulation.py +158 -0
- openfisca_core/simulations/_build_from_variables.py +230 -0
- openfisca_core/simulations/_type_guards.py +298 -0
- openfisca_core/simulations/helpers.py +111 -0
- openfisca_core/simulations/simulation.py +618 -0
- openfisca_core/simulations/simulation_builder.py +855 -0
- openfisca_core/simulations/typing.py +203 -0
- openfisca_core/taxbenefitsystems/__init__.py +26 -0
- openfisca_core/taxbenefitsystems/tax_benefit_system.py +584 -0
- openfisca_core/taxscales/__init__.py +35 -0
- openfisca_core/taxscales/abstract_rate_tax_scale.py +41 -0
- openfisca_core/taxscales/abstract_tax_scale.py +53 -0
- openfisca_core/taxscales/amount_tax_scale_like.py +55 -0
- openfisca_core/taxscales/helpers.py +44 -0
- openfisca_core/taxscales/linear_average_rate_tax_scale.py +76 -0
- openfisca_core/taxscales/marginal_amount_tax_scale.py +34 -0
- openfisca_core/taxscales/marginal_rate_tax_scale.py +286 -0
- openfisca_core/taxscales/rate_tax_scale_like.py +214 -0
- openfisca_core/taxscales/single_amount_tax_scale.py +32 -0
- openfisca_core/taxscales/tax_scale_like.py +65 -0
- openfisca_core/tools/__init__.py +94 -0
- openfisca_core/tools/parallel_plugin.py +55 -0
- openfisca_core/tools/simulation_dumper.py +137 -0
- openfisca_core/tools/test_runner.py +802 -0
- openfisca_core/tracers/__init__.py +40 -0
- openfisca_core/tracers/computation_log.py +196 -0
- openfisca_core/tracers/flat_trace.py +87 -0
- openfisca_core/tracers/full_tracer.py +172 -0
- openfisca_core/tracers/performance_log.py +133 -0
- openfisca_core/tracers/simple_tracer.py +64 -0
- openfisca_core/tracers/trace_node.py +121 -0
- openfisca_core/tracers/tracing_parameter_node_at_instant.py +81 -0
- openfisca_core/types.py +548 -0
- openfisca_core/variables/__init__.py +26 -0
- openfisca_core/variables/config.py +53 -0
- openfisca_core/variables/helpers.py +67 -0
- openfisca_core/variables/tests/__init__.py +0 -0
- openfisca_core/variables/tests/test_definition_period.py +43 -0
- openfisca_core/variables/variable.py +474 -0
- openfisca_core/warnings/__init__.py +25 -0
- openfisca_core/warnings/libyaml_warning.py +2 -0
- openfisca_core/warnings/tempfile_warning.py +2 -0
- openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/CHANGELOG.md +4209 -0
- openfisca_core_test-46.0.0.data/data/share/openfisca/openfisca-core/README.md +152 -0
- openfisca_core_test-46.0.0.dist-info/METADATA +194 -0
- openfisca_core_test-46.0.0.dist-info/RECORD +237 -0
- openfisca_core_test-46.0.0.dist-info/WHEEL +5 -0
- openfisca_core_test-46.0.0.dist-info/entry_points.txt +3 -0
- openfisca_core_test-46.0.0.dist-info/licenses/LICENSE +661 -0
- openfisca_core_test-46.0.0.dist-info/top_level.txt +2 -0
- openfisca_web_api/__init__.py +0 -0
- openfisca_web_api/app.py +226 -0
- openfisca_web_api/errors.py +11 -0
- openfisca_web_api/handlers.py +90 -0
- openfisca_web_api/loader/__init__.py +22 -0
- openfisca_web_api/loader/entities.py +28 -0
- openfisca_web_api/loader/parameters.py +122 -0
- openfisca_web_api/loader/spec.py +168 -0
- openfisca_web_api/loader/tax_benefit_system.py +27 -0
- openfisca_web_api/loader/variables.py +121 -0
- openfisca_web_api/openAPI.yml +434 -0
- openfisca_web_api/scripts/__init__.py +0 -0
- 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
|