Skip to content

Use default arg to select instead of a dummy True condition #1176

@MaxGhenis

Description

@MaxGhenis

In some instances, we use select with a dummy True condition list item, to capture the default. Let's use the optional default arg to numpy.select instead.

Example:
https://github.com/PolicyEngine/openfisca-us/blob/aaf2616aeee5187266f9ff0a8d2b4156291711f9/openfisca_us/variables/household/demographic/person/postpartum/count_days_postpartum.py#L14-L25

Replacement:

        return select(
            [under_60_days, under_12_months],
            [0, 60],
            default=np.inf
        )

Time tests show this improves performance of the select operation by about 10%.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions