Skip to content

Commit

Permalink
test: get index (#1238 #1276 #1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Oct 17, 2024
1 parent f952744 commit 8b7bbc7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions openfisca_core/populations/_core_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def filled_array(
Examples:
>>> import numpy
>>> from openfisca_core import populations as p
>>> from openfisca_core import populations
>>> class Population(p.CorePopulation): ...
>>> class Population(populations.CorePopulation): ...
>>> population = Population(None)
>>> population.count = 3
Expand All @@ -155,6 +155,31 @@ def filled_array(
return numpy.full(self.count, value, dtype)

def get_index(self, id: str) -> int:
"""Return the index of an `id``.
Args:
id: The id to get the index for.
Returns:
int: The index of the id.
Examples:
>>> from openfisca_core import entities, populations
>>> class Person(entities.SingleEntity): ...
>>> person = Person("person", "people", "", "")
>>> population = populations.CorePopulation(person)
>>> population.ids = ["Juan", "Megan", "Brahim"]
>>> population.get_index("Megan")
1
>>> population.get_index("Ibrahim")
Traceback (most recent call last):
ValueError: 'Ibrahim' is not in list
"""
return self.ids.index(id)

# Calculations
Expand Down

0 comments on commit 8b7bbc7

Please sign in to comment.