Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-9397

Config should support enum type fields

    Details

    • Type: Improvement
    • Status: To Do
    • Resolution: Unresolved
    • Fix Version/s: None
    • Component/s: pex_config
    • Labels:
      None

      Description

      Config fields support type int but not int-valued enums. With SWIG this was only a mild nuisance because it treated enums as ints, but pybind11 is more careful. This leads to a need to explicitly cast values for enum fields to int (in the field) and from int to the enum type (when passed to pybind11-wrapped code), which is messy.

      I suggest that enum types be explicitly supported. I suspect the only tricky part will be persistence (which may require casting from between int and the enum type) and specifying arguments on the command line. For single-valued enums one can might be able to persist by name (with an appropriate include at the top of the file) but that would be harder for mask fields (where various enum constants are "or"ed together).

        Attachments

          Activity

          Hide
          krzys Krzysztof Findeisen added a comment - - edited

          It might be tricky because config fields do run-time type checking, and AFAIK there is no easy way to identify a Python class as a pybind11 wrapper for an enum, e.g. there is no "enum" base class to test for.

          Show
          krzys Krzysztof Findeisen added a comment - - edited It might be tricky because config fields do run-time type checking, and AFAIK there is no easy way to identify a Python class as a pybind11 wrapper for an enum, e.g. there is no "enum" base class to test for.
          Hide
          rowen Russell Owen added a comment -

          I agree it's not going to be trivial. For example the enum DateTime.TAI has a type of lsst.daf.base._dateTime.DateTime.Timescale and the only parent class is listed as object. Thus we cannot search for any variant of "enum". I also don't see any obvious methods to test for.

          One possible solution is to add an enum wrapper class to daf_base that can be used when specifying an enum type, e.g. Field(dtype=EnumClass(dafBase.Timesys), ...).

          If that cannot be implemented cleanly, a less flexible alternative is to add a new field type EnumField.

          Show
          rowen Russell Owen added a comment - I agree it's not going to be trivial. For example the enum DateTime.TAI has a type of lsst.daf.base._dateTime.DateTime.Timescale and the only parent class is listed as object . Thus we cannot search for any variant of "enum". I also don't see any obvious methods to test for. One possible solution is to add an enum wrapper class to daf_base that can be used when specifying an enum type, e.g. Field(dtype=EnumClass(dafBase.Timesys), ...) . If that cannot be implemented cleanly, a less flexible alternative is to add a new field type EnumField .

            People

            • Assignee:
              Unassigned
              Reporter:
              rowen Russell Owen
              Watchers:
              Kian-Tat Lim, Krzysztof Findeisen, Pim Schellart [X] (Inactive), Russell Owen
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel