Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions openfisca_core/parameters/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
import traceback

import numpy
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is useful to test pandas here, I suggest we move this as an actual test, and that we require pandas optionally in case we want to run that specific test.


from openfisca_core import parameters, periods
from openfisca_core.errors import ParameterParsingError
from openfisca_core.parameters import config


def contains_nan(vector):
print(vector)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove this print statement?

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 = ''):
Expand Down
20 changes: 6 additions & 14 deletions openfisca_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change (the badly named periods.period function is actually a builder function.


self.tracer.record_calculation_start(variable_name, period)

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions openfisca_core/types/_data.py
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! We should completely get rid of nptyping.

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`.
Expand Down
58 changes: 29 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down