Skip to content

Commit 866927a

Browse files
nicolas-beharGiulio Santo
andauthored
included missing init to the causal exceptions (#212)
* included missing init * including missing type * fix lint * Included return type * exceptions.py: Fixed exceptions typing. * updating changelog and version * fix docstring * including docstring updates * fix failing test Co-authored-by: Giulio Santo <giulio.santo@nubank.com.br>
1 parent ac66293 commit 866927a

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [2.2.1] - 2022-09-06
4+
- **Bug Fix**
5+
- Including a necessary init file to allow the import of the causal cate learners.
6+
- Fix a docstring issue where the description of causal learners were not showing all parameters.
7+
38
## [2.2.0] - 2022-08-25
49
- **Enhancement**
510
- Including Classification S-Learner and T-Learner models to the causal cate learning library.

src/fklearn/causal/cate_learning/meta_learners.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def causal_s_classification_learner(
191191
[1] https://matheusfacure.github.io/python-causality-handbook/21-Meta-Learners.html
192192
193193
[2] https://causalml.readthedocs.io/en/latest/methodology.html
194+
194195
Parameters
195196
----------
196197
df : pd.DataFrame
@@ -369,34 +370,29 @@ def causal_t_classification_learner(
369370
and $M_{1}$ are traditional Machine Learning models such as a LightGBM Classifier and
370371
that $x_{i}$ is the feature set of sample $i$.
371372
372-
References:
373+
**References:**
374+
373375
[1] https://matheusfacure.github.io/python-causality-handbook/21-Meta-Learners.html
376+
374377
[2] https://causalml.readthedocs.io/en/latest/methodology.html
375378
376379
Parameters
377380
----------
378-
379381
df : pd.DataFrame
380382
A Pandas' DataFrame with features and target columns.
381383
The model will be trained to predict the target column
382384
from the features.
383-
384385
treatment_col: str
385386
The name of the column in `df` which contains the names of
386387
the treatments and control to which each data sample was subjected.
387-
388388
control_name: str
389389
The name of the control group.
390-
391390
prediction_column : str
392391
The name of the column with the predictions from the provided learner.
393-
394392
learner: LearnerFnType
395393
A fklearn classification learner function.
396-
397394
treatment_learner: LearnerFnType
398395
An optional fklearn classification learner function.
399-
400396
learner_transformers: List[LearnerFnType]
401397
A list of fklearn transformer functions to be applied after the learner and before estimating the CATE.
402398
This parameter may be useful, for example, to estimate the CATE with calibrated classifiers.
@@ -447,6 +443,6 @@ def p(new_df: pd.DataFrame) -> pd.DataFrame:
447443
return p, p(df), log
448444

449445

450-
causal_t_classification_learner.__doc__ = learner_return_docstring(
446+
causal_t_classification_learner.__doc__ += learner_return_docstring(
451447
"Causal T-Learner Classifier"
452448
)

src/fklearn/exceptions/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
from typing import Any, Dict, List
2+
3+
14
class MultipleTreatmentsError(Exception):
2-
def __init__(self, msg="Data contains multiple treatments.", *args, **kwargs):
5+
def __init__(
6+
self,
7+
msg: str = "Data contains multiple treatments.",
8+
*args: List[Any],
9+
**kwargs: Dict[str, Any]
10+
) -> None:
311
super().__init__(msg, *args, **kwargs)
412

513

614
class MissingControlError(Exception):
715
def __init__(
8-
self, msg="Data does not contain the specified control.", *args, **kwargs
9-
):
16+
self,
17+
msg: str = "Data does not contain the specified control.",
18+
*args: List[Any],
19+
**kwargs: Dict[str, Any]
20+
) -> None:
1021
super().__init__(msg, *args, **kwargs)
1122

1223

1324
class MissingTreatmentError(Exception):
1425
def __init__(
15-
self, msg="Data does not contain the specified treatment.", *args, **kwargs
16-
):
26+
self,
27+
msg: str = "Data does not contain the specified treatment.",
28+
*args: List[Any],
29+
**kwargs: Dict[str, Any]
30+
) -> None:
1731
super().__init__(msg, *args, **kwargs)

src/fklearn/resources/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
2.2.1

tests/validation/test_evaluators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def test_exponential_coefficient_evaluator():
469469

470470
result = exponential_coefficient_evaluator(predictions)
471471

472-
assert result['exponential_coefficient_evaluator__target'] == a1
472+
assert result['exponential_coefficient_evaluator__target'] == pytest.approx(a1)
473473

474474

475475
def test_logistic_coefficient_evaluator():

0 commit comments

Comments
 (0)