diff --git a/openfisca_core/parameters/helpers.py b/openfisca_core/parameters/helpers.py index 75d5a18b73..c3f009cf7b 100644 --- a/openfisca_core/parameters/helpers.py +++ b/openfisca_core/parameters/helpers.py @@ -2,6 +2,7 @@ import traceback import numpy +import pandas as pd from openfisca_core import parameters, periods from openfisca_core.errors import ParameterParsingError @@ -9,10 +10,16 @@ def contains_nan(vector): + print(vector) if numpy.issubdtype(vector.dtype, numpy.record): return any([contains_nan(vector[name]) for name in vector.dtype.names]) else: return numpy.isnan(vector).any() + #print(type(vector), type(vector[0])) + #vector = vector.astype(float) + #return pd.isna(vector).any() + #_vector = numpy.array(vector) + print(type(vector), vector) def load_parameter_file(file_path, name = ''): diff --git a/openfisca_core/simulations/simulation.py b/openfisca_core/simulations/simulation.py index ef1cbbd869..24163c07ba 100644 --- a/openfisca_core/simulations/simulation.py +++ b/openfisca_core/simulations/simulation.py @@ -96,7 +96,8 @@ def calculate(self, variable_name: str, period): """Calculate ``variable_name`` for ``period``.""" if period is not None and not isinstance(period, Period): - period = periods.period(period) + ##period = periods.period(period) + period = Period(period) self.tracer.record_calculation_start(variable_name, period) @@ -270,23 +271,14 @@ def _check_period_consistency(self, period, variable): return # For variables which values are constant in time, all periods are accepted if variable.definition_period == periods.MONTH and period.unit != periods.MONTH: - raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole month. You can use the ADD option to sum '{0}' over the requested period, or change the requested period to 'period.first_month'.".format( - variable.name, - period - )) + raise ValueError(f"Unable to compute variable '{variable.name}' for period {period}: '{variable.name}' must be computed for a whole month. You can use the ADD option to sum '{variable.name}' over the requested period, or change the requested period to 'period.first_month'.") if variable.definition_period == periods.YEAR and period.unit != periods.YEAR: - raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole year. You can use the DIVIDE option to get an estimate of {0} by dividing the yearly value by 12, or change the requested period to 'period.this_year'.".format( - variable.name, - period - )) + raise ValueError(f"Unable to compute variable '{variable.name}' for period {period}: '{variable.name}' must be computed for a whole year. You can use the DIVIDE option to get an estimate of {variable.name} by dividing the yearly value by 12, or change the requested period to 'period.this_year'.") if period.size != 1: - raise ValueError("Unable to compute variable '{0}' for period {1}: '{0}' must be computed for a whole {2}. You can use the ADD option to sum '{0}' over the requested period.".format( - variable.name, - period, - 'month' if variable.definition_period == periods.MONTH else 'year' - )) + _period = 'month' if variable.definition_period == periods.MONTH else 'year' + raise ValueError(f"Unable to compute variable '{variable.name}' for period {period}: '{variable.name}' must be computed for a whole {_period}. You can use the ADD option to sum '{variable.name}' over the requested period.") def _cast_formula_result(self, value, variable): if variable.value_type == Enum and not isinstance(value, EnumArray): diff --git a/openfisca_core/types/_data.py b/openfisca_core/types/_data.py index ff7066d43a..298566aece 100644 --- a/openfisca_core/types/_data.py +++ b/openfisca_core/types/_data.py @@ -1,12 +1,15 @@ from typing import Sequence, TypeVar, Union -from nptyping import types, NDArray as Array +# Modified by Emanuele Cannizzaro on 03/06/2023 +#from typing import types, NDArray as Array +import types +from numpy import ndarray as Array import numpy T = TypeVar("T", bool, bytes, float, int, object, str) -types._ndarray_meta._Type = Union[type, numpy.dtype, TypeVar] +##types._ndarray_meta._Type = Union[type, numpy.dtype, TypeVar] ArrayLike = Union[Array[T], Sequence[T]] """:obj:`typing.Generic`: Type of any castable to :class:`numpy.ndarray`. diff --git a/setup.py b/setup.py index 1723a25aaf..ae686db05f 100644 --- a/setup.py +++ b/setup.py @@ -27,41 +27,41 @@ general_requirements = [ 'PyYAML >= 3.10', - 'dpath >= 1.5.0, < 3.0.0', - 'importlib-metadata < 4.3.0', # Required for Python 3.7 and Flake8 - 'nptyping == 1.4.4', - 'numexpr >= 2.7.0, <= 3.0', - 'numpy >= 1.11, < 1.21', - 'psutil >= 5.4.7, < 6.0.0', - 'pytest >= 4.4.1, < 6.0.0', # For openfisca test - 'sortedcontainers == 2.2.2', - 'typing-extensions >= 4.0.0, < 5.0.0', + 'dpath >= 1.5.0', + 'importlib-metadata >= 4.3.0', # Required for Python 3.7 and Flake8 + 'nptyping >= 1.4.4', + 'numexpr >= 2.7.0', + 'numpy >= 1.11', + 'psutil >= 5.4.7', + 'pytest >= 4.4.1', # For openfisca test + 'sortedcontainers >= 2.2.2', + 'typing-extensions >= 4.0.0', ] api_requirements = [ - 'markupsafe == 2.0.1', # While flask revision < 2 - 'flask == 1.1.4', - 'flask-cors == 3.0.10', - 'gunicorn >= 20.0.0, < 21.0.0', - 'werkzeug >= 1.0.0, < 2.0.0', + 'markupsafe >= 2.0.1', # While flask revision < 2 + 'flask >= 1.1.4', + 'flask-cors >= 3.0.10', + 'gunicorn >= 20.0.0', + 'werkzeug >= 1.0.0', ] dev_requirements = [ - 'autopep8 >= 1.4.0, < 1.6.0', - 'coverage >= 6.0.2, < 7.0.0', - 'darglint == 1.8.0', - 'flake8 >= 4.0.0, < 4.1.0', - 'flake8-bugbear >= 19.3.0, < 20.0.0', - 'flake8-docstrings == 1.6.0', - 'flake8-print >= 3.1.0, < 4.0.0', - 'flake8-rst-docstrings == 0.2.3', - 'idna >= 3.4.0, < 4.0.0', - 'isort >= 5.0.0, < 6.0.0', - 'mypy == 0.910', - 'openapi-spec-validator >= 0.5.0, < 0.6.0', - 'pycodestyle >= 2.8.0, < 2.9.0', - 'pylint == 2.10.2', - 'xdoctest >= 1.0.0, < 2.0.0', + 'autopep8 >= 1.4.0', + 'coverage >= 6.0.2', + 'darglint >= 1.8.0', + 'flake8 >= 4.0.0', + 'flake8-bugbear >= 19.3.0', + 'flake8-docstrings >= 1.6.0', + 'flake8-print >= 3.1.0', + 'flake8-rst-docstrings >= 0.2.3', + 'idna >= 3.4.0', + 'isort >= 5.0.0', + 'mypy >= 0.910', + 'openapi-spec-validator >= 0.5.0', + 'pycodestyle >= 2.8.0', + 'pylint >= 2.10.2', + 'xdoctest >= 1.0.0', ] + api_requirements setup(