-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(enums): move config to general (#1233)
- Loading branch information
1 parent
6480a2c
commit 738652a
Showing
12 changed files
with
133 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Final, final | ||
|
||
import dataclasses | ||
import datetime | ||
|
||
from openfisca_core import indexed_enums as enum | ||
|
||
from . import types as t | ||
|
||
|
||
@final | ||
@dataclasses.dataclass(frozen=True) | ||
class ValueType: | ||
dtype: t.DTypeLike | ||
default: object | ||
json_type: str | ||
formatted_value_type: str | ||
is_period_size_independent: bool | ||
|
||
|
||
value_types: Final = { | ||
bool: ValueType( | ||
dtype=t.DTypeBool, | ||
default=False, | ||
json_type="boolean", | ||
formatted_value_type="Boolean", | ||
is_period_size_independent=True, | ||
), | ||
int: ValueType( | ||
dtype=t.DTypeInt, | ||
default=0, | ||
json_type="integer", | ||
formatted_value_type="Int", | ||
is_period_size_independent=False, | ||
), | ||
float: ValueType( | ||
dtype=t.DTypeFloat, | ||
default=0, | ||
json_type="number", | ||
formatted_value_type="Float", | ||
is_period_size_independent=False, | ||
), | ||
str: ValueType( | ||
dtype=t.DTypeStr, | ||
default="", | ||
json_type="string", | ||
formatted_value_type="String", | ||
is_period_size_independent=True, | ||
), | ||
enum.Enum: ValueType( | ||
dtype=t.DTypeEnum, | ||
default=None, | ||
json_type="string", | ||
formatted_value_type="String", | ||
is_period_size_independent=True, | ||
), | ||
datetime.date: ValueType( | ||
dtype="datetime64[D]", | ||
default=None, | ||
json_type="string", | ||
formatted_value_type="Date", | ||
is_period_size_independent=True, | ||
), | ||
} | ||
|
||
__all__ = ["value_types"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
from openfisca_core.types import Array, DTypeEnum, Enum, EnumArray | ||
from openfisca_core.types import ( | ||
Array, | ||
DTypeBool, | ||
DTypeEnum, | ||
DTypeInt, | ||
DTypeObject, | ||
DTypeStr, | ||
Enum, | ||
EnumArray, | ||
) | ||
|
||
__all__ = ["Array", "DTypeEnum", "Enum", "EnumArray"] | ||
__all__ = [ | ||
"Array", | ||
"DTypeBool", | ||
"DTypeEnum", | ||
"DTypeInt", | ||
"DTypeObject", | ||
"DTypeStr", | ||
"Enum", | ||
"EnumArray", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1 @@ | ||
import datetime | ||
|
||
import numpy | ||
|
||
from openfisca_core import indexed_enums | ||
from openfisca_core.indexed_enums import Enum | ||
|
||
VALUE_TYPES = { | ||
bool: { | ||
"dtype": numpy.bool_, | ||
"default": False, | ||
"json_type": "boolean", | ||
"formatted_value_type": "Boolean", | ||
"is_period_size_independent": True, | ||
}, | ||
int: { | ||
"dtype": numpy.int32, | ||
"default": 0, | ||
"json_type": "integer", | ||
"formatted_value_type": "Int", | ||
"is_period_size_independent": False, | ||
}, | ||
float: { | ||
"dtype": numpy.float32, | ||
"default": 0, | ||
"json_type": "number", | ||
"formatted_value_type": "Float", | ||
"is_period_size_independent": False, | ||
}, | ||
str: { | ||
"dtype": object, | ||
"default": "", | ||
"json_type": "string", | ||
"formatted_value_type": "String", | ||
"is_period_size_independent": True, | ||
}, | ||
Enum: { | ||
"dtype": indexed_enums.ENUM_ARRAY_DTYPE, | ||
"json_type": "string", | ||
"formatted_value_type": "String", | ||
"is_period_size_independent": True, | ||
}, | ||
datetime.date: { | ||
"dtype": "datetime64[D]", | ||
"default": datetime.date.fromtimestamp(0), # 0 == 1970-01-01 | ||
"json_type": "string", | ||
"formatted_value_type": "Date", | ||
"is_period_size_independent": True, | ||
}, | ||
} | ||
|
||
|
||
FORMULA_NAME_PREFIX = "formula" |
Oops, something went wrong.