Check if the 'factor' column is missing in the DataFrame.
(self)
| 145 | return None |
| 146 | |
| 147 | def check_missing_factor(self) -> Optional[pd.DataFrame]: |
| 148 | """Check if the 'factor' column is missing in the DataFrame.""" |
| 149 | result_dict = { |
| 150 | "instruments": [], |
| 151 | "missing_factor_col": [], |
| 152 | "missing_factor_data": [], |
| 153 | } |
| 154 | for filename, df in self.data.items(): |
| 155 | if "000300" in filename or "000903" in filename or "000905" in filename: |
| 156 | continue |
| 157 | if "factor" not in df.columns: |
| 158 | result_dict["instruments"].append(filename) |
| 159 | result_dict["missing_factor_col"].append(True) |
| 160 | if df["factor"].isnull().all(): |
| 161 | if filename in result_dict["instruments"]: |
| 162 | result_dict["missing_factor_data"].append(True) |
| 163 | else: |
| 164 | result_dict["instruments"].append(filename) |
| 165 | result_dict["missing_factor_col"].append(False) |
| 166 | result_dict["missing_factor_data"].append(True) |
| 167 | |
| 168 | result_df = pd.DataFrame(result_dict).set_index("instruments") |
| 169 | if not result_df.empty: |
| 170 | return result_df |
| 171 | else: |
| 172 | logger.info(f"✅ The `factor` column already exists and is not empty.") |
| 173 | return None |
| 174 | |
| 175 | def check_data(self): |
| 176 | check_missing_data_result = self.check_missing_data() |
no test coverage detected