py_wlc.generic package¶
Submodules¶
py_wlc.generic.growth module¶
Generic functionality for modelling growth series.
-
class
py_wlc.generic.growth.IndexSeries(base_year, rates, initial_value, year_zero=None)[source]¶ Bases:
objectGrowth rates and factors for indexation series.
The
_ratesdictionary is fully-populated at initialisation, but the_valuesdictionary is filled lazily - values are only calculated as needed.The class supports a
Mapping-like interface; factors can be accessed withvalue = growth_rate[year]orvalue = growth_rate.get(year, default).Note
The term ‘relative year’ refers to the year relative to
year_zeroe.g.3. The term ‘absolute year’ refers to a calendar year, e.g.2013. Relative years are used internally, absolute years for the external interface.Parameters: - base_year (
int) – the year in which the value is equal to theinitial_value - rates (
dictofint:float) – the growth rates to use, keyed by relative year - initial_value (
float) – the first value for the output series. - year_zero (
int, optional) – the zeroth year for accessing growth rates. Defaults tobase_year.
-
base_year¶ intThe base year for growth, i.e. the year in which the value is the
initial_value.
-
year_zero¶ intThe zeroth year for growth, i.e. the year from which the rates are selected from
_rates.
-
_rates¶ dictofint:floatThe growth rates, where the key is the relative start year and the value is the rate to apply.
-
_initial_rate¶ floatThe growth rate corresponding to the first year in the
ratesdictionary.
-
_final_rate¶ floatThe growth rate corresponding to the last year in the
ratesdictionary.
-
_values¶ dictofint:floatThe values, keyed by year.
-
get(year, default=None)[source]¶ Retrieve value or supplied default for given year.
Parameters: - year (int) – The year to retrieve the value for.
- default (float or None, optional) – The value to return if
retrieval fails. Defaults to
None.
Returns: The retrieved or
defaultvalue.Return type: float or None
- base_year (
Module contents¶
Generic functionality supporting the core modelling.
-
class
py_wlc.generic.ExtendedDict[source]¶ Bases:
dictDictionary subclass that provides values beyond defined keys.
Provides values outside the predefined range, according to the following rules:
- If the key is larger than the largest key in the dictionary, the value from the largest key is returned.
- If the key is smaller than the smallest key in the dictionary, the value from the smallest key is returned.
- If the key is between the smallest and largest keys in the
dictionary but no value is found, a
KeyErroroccurs.
-
copy()[source]¶ Create a copy of the extended dictionary.
Returns: A new class instance. Return type: ExtendedDict