-
Notifications
You must be signed in to change notification settings - Fork 82
Small changes to get it working on latest version of python and packages #1183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,24 @@ | |
import traceback | ||
|
||
import numpy | ||
import pandas as pd | ||
|
||
from openfisca_core import parameters, periods | ||
from openfisca_core.errors import ParameterParsingError | ||
from openfisca_core.parameters import config | ||
|
||
|
||
def contains_nan(vector): | ||
print(vector) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please remove this |
||
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 = ''): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change (the badly named |
||
|
||
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): | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this! We should completely get rid of |
||
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`. | ||
|
There was a problem hiding this comment.
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 requirepandas
optionally in case we want to run that specific test.