|
21 | 21 | from chebai.preprocessing import reader as dr |
22 | 22 |
|
23 | 23 |
|
24 | | -@dataclass |
25 | 24 | class XYBaseDataModule(LightningDataModule): |
26 | 25 | """ |
27 | 26 | Base class for data modules. |
@@ -124,49 +123,6 @@ def __init__( |
124 | 123 | self._prepare_data_flag = 1 |
125 | 124 | self._setup_data_flag = 1 |
126 | 125 |
|
127 | | - def __init_subclass__(cls, *args, **kwargs): |
128 | | - """ |
129 | | - This method ensures that the '_call_data_processing_methods' is called only for the final subclass |
130 | | - in the class hierarchy. It overrides the default __init__ behavior to add custom initialization logic. |
131 | | -
|
132 | | - - The method saves the original `__init__` method of the class and then defines a new `__init__` method. |
133 | | - - This new `__init__` method calls the original `__init__` method of the class and then checks if the |
134 | | - current class is the final subclass (i.e., not a subclass of a subclass). |
135 | | - - If it's the final class, it invokes the `_call_data_processing_methods` method to perform any necessary |
136 | | - data processing tasks. |
137 | | - """ |
138 | | - super().__init_subclass__(*args, **kwargs) |
139 | | - original_init = cls.__init__ |
140 | | - |
141 | | - # Creates updated definition for init method |
142 | | - def new_init(self, *args, **kwargs): |
143 | | - original_init(self, *args, **kwargs) # Call the original __init__ |
144 | | - if type(self) == cls: # Only run method if it's the final class |
145 | | - self._call_data_processing_methods(*args, **kwargs) |
146 | | - |
147 | | - cls.__init__ = new_init |
148 | | - |
149 | | - def _call_data_processing_methods(self, *args, **kwargs) -> None: |
150 | | - """ |
151 | | - Calls data processing methods unless explicitly skipped. |
152 | | -
|
153 | | - - Skips execution if `_skip_data_methods_on_init` is `True` (e.g., for unit tests). |
154 | | - - Otherwise, calls `prepare_data()` and `setup()` for data preparation. |
155 | | -
|
156 | | - Note: This method is called after the instantiation of most derived class is completed. |
157 | | - """ |
158 | | - if kwargs.get("_skip_data_methods_on_init", False): |
159 | | - print( |
160 | | - f"Skipping data methods of class '{os.path.join(self.base_dir, self._name)}' during initialization" |
161 | | - ) |
162 | | - return |
163 | | - |
164 | | - print( |
165 | | - f"Calling data method of class {os.path.join(self.base_dir, self._name)} during initialization" |
166 | | - ) |
167 | | - self.prepare_data(*args, **kwargs) |
168 | | - self.setup(*args, **kwargs) |
169 | | - |
170 | 126 | @property |
171 | 127 | def num_of_labels(self): |
172 | 128 | assert self._num_of_labels is not None, "num of labels must be set" |
|
0 commit comments