Skip to content

Error when trying to encode scalar Enum arrays #922

@bonjourmauko

Description

@bonjourmauko

The following code fails for scalar Enum arrays (without dimension):

if len(array) > 0 and cls.__name__ is array[0].__class__.__name__:

A real-life example of this bug:

https://github.com/openfisca/openfisca-france/blob/7918eec5be4c2cdeb65da9fb023cfbfcce537156/openfisca_france/model/prestations/logement_social.py#L71-L81

You can reproduce the issue with the following code:

from numpy import array, atleast_1d

from openfisca_core.indexed_enums import Enum

class Greetings(Enum):
    hola = "Hola"
    chao = "Chao"

greeting = array(Greetings.hola)
greeting.size # 1
len(greeting) # TypeError: len() of unsized object
atleast_1d(greeting).size # 1
len(atleast_1d(greeting)) # 1

What's the expected behaviour here?

  1. We're expecting an array with at least one dimension.
  2. We should make sure we cast or take into account scalar arrays.

cc @Morendil @fpagnoux

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:fixBugs are defects and failure demand.level:starterSuited for beginners and new contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions