reV.utilities.FieldEnum
- class FieldEnum(value)[source]
-
Base Field enum with some mapping methods.
Methods
map_to
(other)Return a rename map from this enum to another.
map_from
(other)Map from a dictionary of name / member pairs to this enum.
- classmethod map_to(other)[source]
Return a rename map from this enum to another.
Mapping is performed on matching enum names. In other words, if both enums have a ONE attribute, this will be mapped from one enum to another.
- Parameters:
other (
Enum
) –Enum
subclass with__members__
attribute.- Returns:
dict – Dictionary mapping matching values from one enum to another.
Examples
>>> class Test1(FieldEnum): >>> ONE = "one_x" >>> TWO = "two" >>> >>> class Test2(Enum): >>> ONE = "one_y" >>> THREE = "three" >>> >>> Test1.map_to(Test2) {<Test1.ONE: 'one_x'>: <Test2.ONE: 'one_y'>}
- classmethod map_from(other)[source]
Map from a dictionary of name / member pairs to this enum.
- Parameters:
other (dict) – Dictionary mapping key values (typically old aliases) to enum values. For example,
{'sc_gid': 'SC_GID'}
would return a dictionary that maps'sc_gid'
to theSC_GID
member of this enum.- Returns:
dict – Mapping of input dictionary keys to member values of this enum.
Examples
>>> class Test(FieldEnum): >>> ONE = "one_x" >>> TWO = "two_y" >>> >>> Test.map_from({1: "ONE", 2: "TWO"}) {1: <Test.ONE: 'one_x'>, 2: <Test.TWO: 'two_y'>}