Skip to content

Commit ed715fd

Browse files
committed
docs(exp): add docs to experimental
1 parent 86d5447 commit ed715fd

File tree

18 files changed

+99
-100
lines changed

18 files changed

+99
-100
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,7 @@ Add `--only-variables` and `--ignore-variables` options to `openfisca-run-test`
25782578
For instance:
25792579

25802580
```
2581-
from openfisca_core.memory_config import MemoryConfig
2581+
from openfisca_core.experimental import MemoryConfig
25822582

25832583
simulation = ... # create a Simulation object
25842584

openfisca_core/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""The most widely adopted free and open-source engine to write rules as code."""
2+
3+
from openfisca_core.commons import (
4+
apply_thresholds,
5+
average_rate,
6+
concat,
7+
marginal_rate,
8+
switch,
9+
)
10+
11+
from . import types
12+
from .experimental import MemoryConfig
13+
from .simulations import (
14+
Simulation,
15+
SimulationBuilder,
16+
calculate_output_add,
17+
calculate_output_divide,
18+
check_type,
19+
transform_to_strict_syntax,
20+
)
21+
22+
__all__ = [
23+
"MemoryConfig",
24+
"Simulation",
25+
"SimulationBuilder",
26+
"apply_thresholds",
27+
"average_rate",
28+
"calculate_output_add",
29+
"calculate_output_divide",
30+
"check_type",
31+
"concat",
32+
"marginal_rate",
33+
"switch",
34+
"transform_to_strict_syntax",
35+
"types",
36+
]
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
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
1+
"""Experimental features of OpenFisca-Core."""
232

24-
from .memory_config import MemoryConfig # noqa: F401
3+
from ._errors import MemoryConfigWarning
4+
from ._memory_config import MemoryConfig
5+
6+
__all__ = [
7+
"MemoryConfig",
8+
"MemoryConfigWarning",
9+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
class MemoryConfigWarning(UserWarning):
22
"""Custom warning for MemoryConfig."""
3+
4+
5+
__all__ = ["MemoryConfigWarning"]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Iterable
4+
5+
import warnings
6+
7+
from ._errors import MemoryConfigWarning
8+
9+
10+
class MemoryConfig:
11+
"""Experimental memory configuration."""
12+
13+
#: Maximum memory occupation allowed.
14+
max_memory_occupation: float
15+
16+
#: Priority variables.
17+
priority_variables: frozenset[str]
18+
19+
#: Variables to drop.
20+
variables_to_drop: frozenset[str]
21+
22+
def __init__(
23+
self,
24+
max_memory_occupation: str | float,
25+
priority_variables: Iterable[str] = frozenset(),
26+
variables_to_drop: Iterable[str] = frozenset(),
27+
) -> None:
28+
message = [
29+
"Memory configuration is a feature that is still currently under "
30+
"experimentation. You are very welcome to use it and send us "
31+
"precious feedback, but keep in mind that the way it is used might "
32+
"change without any major version bump.",
33+
]
34+
warnings.warn(" ".join(message), MemoryConfigWarning, stacklevel=2)
35+
36+
self.max_memory_occupation = float(max_memory_occupation)
37+
if self.max_memory_occupation > 1:
38+
msg = "max_memory_occupation must be <= 1"
39+
raise ValueError(msg)
40+
self.max_memory_occupation_pc = self.max_memory_occupation * 100
41+
self.priority_variables = frozenset(priority_variables)
42+
self.variables_to_drop = frozenset(variables_to_drop)

openfisca_core/experimental/memory_config.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

openfisca_core/formula_helpers.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

openfisca_core/memory_config.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

openfisca_core/rates.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

openfisca_core/simulation_builder.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

openfisca_core/tools/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pytest
1818

1919
from openfisca_core.errors import SituationParsingError, VariableNotFound
20-
from openfisca_core.simulation_builder import SimulationBuilder
20+
from openfisca_core.simulations import SimulationBuilder
2121
from openfisca_core.tools import assert_near
2222
from openfisca_core.warnings import LibYAMLWarning
2323

openfisca_core/warnings/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
# See: https://www.python.org/dev/peps/pep-0008/#imports
2323

2424
from .libyaml_warning import LibYAMLWarning # noqa: F401
25-
from .memory_warning import MemoryConfigWarning # noqa: F401
2625
from .tempfile_warning import TempfileWarning # noqa: F401

openfisca_tasks/lint.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ lint-doc: \
2121
lint-doc-commons \
2222
lint-doc-data_storage \
2323
lint-doc-entities \
24+
lint-doc-experimental \
2425
lint-doc-indexed_enums \
2526
;
2627

@@ -43,6 +44,7 @@ check-types:
4344
@python -m mypy \
4445
openfisca_core/commons \
4546
openfisca_core/data_storage \
47+
openfisca_core/experimental \
4648
openfisca_core/entities \
4749
openfisca_core/periods \
4850
openfisca_core/types.py

openfisca_tasks/test_code.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test-core: $(shell git ls-files "*test_*.py")
3838
@python -m pytest --capture=no \
3939
openfisca_core/commons \
4040
openfisca_core/data_storage \
41+
openfisca_core/experimental \
4142
openfisca_core/entities \
4243
openfisca_core/holders \
4344
openfisca_core/indexed_enums \

openfisca_web_api/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dpath.util
22

33
from openfisca_core.indexed_enums import Enum
4-
from openfisca_core.simulation_builder import SimulationBuilder
4+
from openfisca_core.simulations import SimulationBuilder
55

66

77
def calculate(tax_benefit_system, input_data: dict) -> dict:

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ ignore =
2727
in-place = true
2828
include-in-doctest =
2929
openfisca_core/commons
30+
openfisca_core/data_storage
3031
openfisca_core/entities
32+
openfisca_core/experimental
3133
openfisca_core/holders
3234
openfisca_core/indexed_enums
3335
openfisca_core/periods

tests/core/test_holders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from openfisca_core import holders, periods, tools
88
from openfisca_core.errors import PeriodMismatchError
9+
from openfisca_core.experimental import MemoryConfig
910
from openfisca_core.holders import Holder
10-
from openfisca_core.memory_config import MemoryConfig
1111
from openfisca_core.periods import DateUnit
1212
from openfisca_core.simulations import SimulationBuilder
1313

tests/core/variables/test_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from openfisca_country_template.entities import Person
88

99
from openfisca_core.periods import DateUnit
10-
from openfisca_core.simulation_builder import SimulationBuilder
10+
from openfisca_core.simulations import SimulationBuilder
1111
from openfisca_core.tools import assert_near
1212
from openfisca_core.variables import Variable
1313

0 commit comments

Comments
 (0)