Skip to content

Commit f24c898

Browse files
committed
test: get index (#1238 #1276 #1277)
1 parent 75da38d commit f24c898

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

openfisca_core/populations/_core_population.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def filled_array(
132132
Examples:
133133
>>> import numpy
134134
135-
>>> from openfisca_core import populations as p
135+
>>> from openfisca_core import populations
136136
137-
>>> class Population(p.CorePopulation): ...
137+
>>> class Population(populations.CorePopulation): ...
138138
139139
>>> population = Population(None)
140140
>>> population.count = 3
@@ -155,6 +155,31 @@ def filled_array(
155155
return numpy.full(self.count, value, dtype)
156156

157157
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+
"""
158183
return self.ids.index(id)
159184

160185
# Calculations

0 commit comments

Comments
 (0)