Agg data by specific method.
(data: IndexData, method: str)
| 182 | |
| 183 | @staticmethod |
| 184 | def _agg_data(data: IndexData, method: str) -> Union[IndexData, np.ndarray, None]: |
| 185 | """Agg data by specific method.""" |
| 186 | # FIXME: why not call the method of data directly? |
| 187 | if method == "sum": |
| 188 | return np.nansum(data) |
| 189 | elif method == "mean": |
| 190 | return np.nanmean(data) |
| 191 | elif method == "last": |
| 192 | # FIXME: I've never seen that this method was called. |
| 193 | # Please merge it with "ts_data_last" |
| 194 | return data[-1] |
| 195 | elif method == "all": |
| 196 | return data.all() |
| 197 | elif method == "ts_data_last": |
| 198 | valid_data = data.loc[~data.isna().data.astype(bool)] |
| 199 | if len(valid_data) == 0: |
| 200 | return None |
| 201 | else: |
| 202 | return valid_data.iloc[-1] |
| 203 | else: |
| 204 | raise ValueError(f"{method} is not supported") |
| 205 | |
| 206 | |
| 207 | class BaseSingleMetric: |