@@ -132,9 +132,9 @@ def filled_array(
132
132
Examples:
133
133
>>> import numpy
134
134
135
- >>> from openfisca_core import populations as p
135
+ >>> from openfisca_core import populations
136
136
137
- >>> class Population(p .CorePopulation): ...
137
+ >>> class Population(populations .CorePopulation): ...
138
138
139
139
>>> population = Population(None)
140
140
>>> population.count = 3
@@ -155,6 +155,31 @@ def filled_array(
155
155
return numpy .full (self .count , value , dtype )
156
156
157
157
def get_index (self , id : str ) -> int :
158
+ """Return the index of an `id``.
159
+
160
+ Args:
161
+ id: The id to get the index for.
162
+
163
+ Returns:
164
+ int: The index of the id.
165
+
166
+ Examples:
167
+ >>> from openfisca_core import entities, populations
168
+
169
+ >>> class Person(entities.SingleEntity): ...
170
+
171
+ >>> person = Person("person", "people", "", "")
172
+ >>> population = populations.CorePopulation(person)
173
+ >>> population.ids = ["Juan", "Megan", "Brahim"]
174
+
175
+ >>> population.get_index("Megan")
176
+ 1
177
+
178
+ >>> population.get_index("Ibrahim")
179
+ Traceback (most recent call last):
180
+ ValueError: 'Ibrahim' is not in list
181
+
182
+ """
158
183
return self .ids .index (id )
159
184
160
185
# Calculations
0 commit comments