generated from gmartinsribeiro/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathenum.py
More file actions
77 lines (55 loc) · 1.82 KB
/
enum.py
File metadata and controls
77 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Custom implementations of Enums.
"""
from enum import Enum
class PredictionTask(Enum):
"Enum of supported prediction tasks."
CLASSIFICATION = 'classification'
REGRESSION = 'regression'
class DataFrameType(Enum):
"Enum of supported dataset types."
TABULAR = 'tabular'
TIMESERIES = 'timeseries'
class OrderedEnum(Enum):
"Enum with support for ordering."
def __ge__(self, other):
if self.__class__ is other.__class__:
return self.value >= other.value
return NotImplemented
def __gt__(self, other):
if self.__class__ is other.__class__:
return self.value > other.value
return NotImplemented
def __le__(self, other):
if self.__class__ is other.__class__:
return self.value <= other.value
return NotImplemented
def __lt__(self, other):
if self.__class__ is other.__class__:
return self.value < other.value
return NotImplemented
class StringEnum(Enum):
"""Enum that allows case-insensitive string lookup."""
@classmethod
def _missing_(cls, value):
if isinstance(value, str):
upper_value = value.upper()
key = cls.find_member(upper_value)
if key is not None:
return key
lower_value = value.lower()
key = cls.find_member(lower_value)
if key is not None:
return key
raise ValueError(f"{value} is not a valid {cls.__name__}")
@classmethod
def find_member(cls, value: str):
"""Find an enum member by its string value.
Args:
value: The string value to look up
Returns:
The enum member if found, None otherwise
"""
if value in cls.__members__:
return cls(value)
return None