@@ -37,13 +37,28 @@ def __setitem__(self, key: int, value: ActionBase) -> None:
3737 """
3838 self .actions [key ] = value
3939
40- def add (self , action : ActionBase ) -> None :
40+ def get_action_by_column_name (self , column_name : str ) -> ActionBase :
4141 """
42- Add a new action in the space
43- :param action:
44- :return:
42+ Get the action that corresponds to the column with
43+ the given name. Raises ValueError if such an action does not
44+ exist
45+ :param column_name: The column name to look for
46+ :return: The action that corresponds to this name
4547 """
4648
49+ for action in self .actions :
50+ if action .column_name == column_name :
51+ return action
52+
53+ raise ValueError ("No action exists for column={0}" .format (column_name ))
54+
55+ def add (self , action : ActionBase ) -> None :
56+ """
57+ Add a new action in the space. Throws ValueError if the action space
58+ is full
59+ :param action: the action to add
60+ :return: None
61+ """
4762 if len (self .actions ) >= self .n :
4863 raise ValueError ("Action space is saturated. You cannot add a new action" )
4964
@@ -69,24 +84,32 @@ def sample_and_get(self) -> ActionBase:
6984 return self .actions [action_idx ]
7085
7186 def get_non_exhausted_actions (self ) -> list :
72-
87+ """
88+ Returns a list of actions that have not exhausted the
89+ transformations that apply on a column.
90+ :return: list of actions. List may be empty. Client code should handle this
91+ """
7392 actions_ = []
74-
7593 for action in self .actions :
7694 if not action .is_exhausted ():
7795 actions_ .append (action )
7896
7997 return actions_
8098
8199 def sample_and_get_non_exhausted (self ) -> ActionBase :
82-
100+ """
101+ Sample an action from the non exhausted actions
102+ :return: A non-exhausted action
103+ """
83104 actions = self .get_non_exhausted_actions ()
84105 return np .random .choice (actions )
85106
86- def is_exhausted (self ):
87-
107+ def is_exhausted (self ) -> bool :
108+ """
109+ Returns true if all the actions in the space are exhausted
110+ :return:
111+ """
88112 finished = True
89-
90113 for action in self .actions :
91114 if not action .is_exhausted ():
92115 return False
@@ -99,5 +122,5 @@ def reset(self) -> None:
99122 :return:
100123 """
101124 for action in self .actions :
102- action .reinit ()
125+ action .reinitialize ()
103126
0 commit comments