Skip to content

Commit

Permalink
work on types
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMount committed Jan 6, 2022
1 parent 94162a8 commit 4c94392
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 108 deletions.
2 changes: 1 addition & 1 deletion coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ pkg/vtreat/vtreat_impl.py 710 78 89%
TOTAL 1410 154 89%


============================= 33 passed in 22.33s ==============================
============================= 33 passed in 21.03s ==============================
80 changes: 23 additions & 57 deletions docs/vtreat/vtreat_impl.html

Large diffs are not rendered by default.

33 changes: 8 additions & 25 deletions pkg/build/lib/vtreat/vtreat_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(
self.extra_args_ = None
self.params_ = None


def transform(self, data_frame: pandas.DataFrame) -> pandas.DataFrame:
"""
return a transformed data frame
Expand Down Expand Up @@ -142,13 +141,13 @@ class TreatmentPlan:
xforms: Tuple[VarTransform, ...]

def __init__(
self,
*,
outcome_name: Optional[str] = None,
cols_to_copy: Optional[Iterable[str]] = None,
num_list: Optional[Iterable[str]] = None,
cat_list: Optional[Iterable[str]] = None,
xforms: Iterable[Optional[VarTransform]]):
self,
*,
outcome_name: Optional[str] = None,
cols_to_copy: Optional[Iterable[str]] = None,
num_list: Optional[Iterable[str]] = None,
cat_list: Optional[Iterable[str]] = None,
xforms: Iterable[Optional[VarTransform]]):
self.outcome_name = outcome_name
if cols_to_copy is None:
self.cols_to_copy = tuple()
Expand Down Expand Up @@ -801,11 +800,9 @@ def fit_numeric_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
if "impact_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_regression_impact_code(
incoming_column_name=vi,
Expand All @@ -816,7 +813,6 @@ def fit_numeric_outcome_treatment(
)
)
if "deviation_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_regression_deviation_code(
incoming_column_name=vi,
Expand All @@ -827,12 +823,10 @@ def fit_numeric_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -896,12 +890,10 @@ def fit_binomial_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
extra_args = {"outcome_target": outcome_target, "var_suffix": ""}
for vi in cat_list:
if "logit_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_binomial_impact_code(
incoming_column_name=vi,
Expand All @@ -912,12 +904,10 @@ def fit_binomial_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -983,7 +973,6 @@ def fit_multinomial_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
for outcome in outcomes:
Expand All @@ -992,7 +981,6 @@ def fit_multinomial_outcome_treatment(
"outcome_target": outcome,
"var_suffix": ("_" + str(outcome)),
}
# noinspection PyTypeChecker
xforms.append(
fit_binomial_impact_code(
incoming_column_name=vi,
Expand All @@ -1003,12 +991,10 @@ def fit_multinomial_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -1070,16 +1056,13 @@ def fit_unsupervised_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -1406,7 +1389,7 @@ def describe_ut(ut):


def pseudo_score_plan_variables(
*, cross_frame, plan:TreatmentPlan, params: Dict[str, Any]
*, cross_frame, plan: TreatmentPlan, params: Dict[str, Any]
) -> pandas.DataFrame:
"""
Build a score frame look-alike for unsupervised case.
Expand Down
Binary file modified pkg/dist/vtreat-1.2.0-py3-none-any.whl
Binary file not shown.
Binary file modified pkg/dist/vtreat-1.2.0.tar.gz
Binary file not shown.
33 changes: 8 additions & 25 deletions pkg/vtreat/vtreat_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(
self.extra_args_ = None
self.params_ = None


def transform(self, data_frame: pandas.DataFrame) -> pandas.DataFrame:
"""
return a transformed data frame
Expand Down Expand Up @@ -142,13 +141,13 @@ class TreatmentPlan:
xforms: Tuple[VarTransform, ...]

def __init__(
self,
*,
outcome_name: Optional[str] = None,
cols_to_copy: Optional[Iterable[str]] = None,
num_list: Optional[Iterable[str]] = None,
cat_list: Optional[Iterable[str]] = None,
xforms: Iterable[Optional[VarTransform]]):
self,
*,
outcome_name: Optional[str] = None,
cols_to_copy: Optional[Iterable[str]] = None,
num_list: Optional[Iterable[str]] = None,
cat_list: Optional[Iterable[str]] = None,
xforms: Iterable[Optional[VarTransform]]):
self.outcome_name = outcome_name
if cols_to_copy is None:
self.cols_to_copy = tuple()
Expand Down Expand Up @@ -801,11 +800,9 @@ def fit_numeric_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
if "impact_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_regression_impact_code(
incoming_column_name=vi,
Expand All @@ -816,7 +813,6 @@ def fit_numeric_outcome_treatment(
)
)
if "deviation_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_regression_deviation_code(
incoming_column_name=vi,
Expand All @@ -827,12 +823,10 @@ def fit_numeric_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -896,12 +890,10 @@ def fit_binomial_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
extra_args = {"outcome_target": outcome_target, "var_suffix": ""}
for vi in cat_list:
if "logit_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_binomial_impact_code(
incoming_column_name=vi,
Expand All @@ -912,12 +904,10 @@ def fit_binomial_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -983,7 +973,6 @@ def fit_multinomial_outcome_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
for outcome in outcomes:
Expand All @@ -992,7 +981,6 @@ def fit_multinomial_outcome_treatment(
"outcome_target": outcome,
"var_suffix": ("_" + str(outcome)),
}
# noinspection PyTypeChecker
xforms.append(
fit_binomial_impact_code(
incoming_column_name=vi,
Expand All @@ -1003,12 +991,10 @@ def fit_multinomial_outcome_treatment(
)
)
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -1070,16 +1056,13 @@ def fit_unsupervised_treatment(
imputation_map=imputation_map,
)
if xform is not None:
# noinspection PyTypeChecker
xforms.append(xform)
for vi in cat_list:
if "prevalence_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_prevalence_code(incoming_column_name=vi, x=numpy.asarray(X[vi]))
)
if "indicator_code" in params["coders"]:
# noinspection PyTypeChecker
xforms.append(
fit_indicator_code(
incoming_column_name=vi,
Expand Down Expand Up @@ -1406,7 +1389,7 @@ def describe_ut(ut):


def pseudo_score_plan_variables(
*, cross_frame, plan:TreatmentPlan, params: Dict[str, Any]
*, cross_frame, plan: TreatmentPlan, params: Dict[str, Any]
) -> pandas.DataFrame:
"""
Build a score frame look-alike for unsupervised case.
Expand Down

0 comments on commit 4c94392

Please sign in to comment.