|
1 | 1 | __all__ = ["DawidSkene", "OneCoinDawidSkene"] |
2 | 2 |
|
3 | | -from typing import Any, List, Literal, Optional, cast |
| 3 | +from typing import Any, List, Literal, Optional, Tuple, cast |
4 | 4 |
|
5 | 5 | import attr |
6 | 6 | import numpy as np |
@@ -235,7 +235,7 @@ def _evidence_lower_bound( |
235 | 235 | priors = priors.rename(index={True: "True", False: "False"}, copy=False) |
236 | 236 | priors.clip(lower=_EPS, inplace=True) |
237 | 237 |
|
238 | | - joined.loc[:, priors.index] = joined.loc[:, priors.index].add(np.log(priors)) # type: ignore |
| 238 | + joined.loc[:, priors.index] = joined.loc[:, priors.index].add(np.log(priors)) |
239 | 239 |
|
240 | 240 | joined.set_index(["task", "worker"], inplace=True) |
241 | 241 | joint_expectation = ( |
@@ -487,25 +487,29 @@ class OneCoinDawidSkene(DawidSkene): |
487 | 487 | """ |
488 | 488 |
|
489 | 489 | @staticmethod |
490 | | - def _assign_skills(row: "pd.Series[Any]", skills: pd.DataFrame) -> pd.DataFrame: |
| 490 | + def _assign_skills( |
| 491 | + row: "pd.Series[Any]", skills: "pd.Series[Any]" |
| 492 | + ) -> "pd.Series[Any]": |
491 | 493 | """ |
492 | 494 | Assigns user skills to error matrix row by row. |
493 | 495 | """ |
494 | 496 | num_categories = len(row) |
495 | 497 | for column_name, _ in row.items(): |
496 | | - if column_name == row.name[1]: # type: ignore |
497 | | - row[column_name] = skills[row.name[0]] # type: ignore |
| 498 | + if column_name == cast(Tuple[Any, Any], row.name)[1]: |
| 499 | + row[column_name] = skills.loc[cast(Tuple[Any, Any], row.name)[0]] |
498 | 500 | else: |
499 | | - row[column_name] = (1 - skills[row.name[0]]) / (num_categories - 1) # type: ignore |
500 | | - return row # type: ignore |
| 501 | + row[column_name] = ( |
| 502 | + 1 - skills.loc[cast(Tuple[Any, Any], row.name)[0]] |
| 503 | + ) / (num_categories - 1) |
| 504 | + return row |
501 | 505 |
|
502 | 506 | @staticmethod |
503 | 507 | def _process_skills_to_errors( |
504 | 508 | data: pd.DataFrame, probas: pd.DataFrame, skills: "pd.Series[Any]" |
505 | 509 | ) -> pd.DataFrame: |
506 | 510 | errors = DawidSkene._m_step(data, probas) |
507 | 511 |
|
508 | | - errors = errors.apply(OneCoinDawidSkene._assign_skills, args=(skills,), axis=1) # type: ignore |
| 512 | + errors = errors.apply(OneCoinDawidSkene._assign_skills, args=(skills,), axis=1) |
509 | 513 | errors.clip(lower=_EPS, upper=1 - _EPS, inplace=True) |
510 | 514 |
|
511 | 515 | return errors |
|
0 commit comments