Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Fixing get_params and adding a DataPreparer test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cchoquette committed Aug 7, 2019
1 parent a07f0cb commit 98fe73e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
8 changes: 8 additions & 0 deletions foreshadow/preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ def __init__(
# ('model_selector', modeler_kwargs_)
] # TODO add each of these components
)

def _get_params(self, attr, deep=True):
# attr will be 'steps' if called from pipeline.get_params()
out = super()._get_params(attr, deep)
steps = getattr(self, attr)
out.update({"steps": steps}) # manually
# adding steps to the get_params()
return out
4 changes: 3 additions & 1 deletion foreshadow/steps/feature_engineerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def group_by(iterable, column_sharer_key):

columns = X.columns.values.tolist()
columns_by_domain = group_by(columns, "domain")
print(columns_by_domain)

columns_by_domain_and_intent = defaultdict(list)
for domain in columns_by_domain:
columns_by_intent = group_by(columns_by_domain[domain], "intent")
print(columns_by_intent)
for intent in columns_by_intent:
columns_by_domain_and_intent[
domain + "_" + intent
str(domain) + "_" + intent
] += columns_by_intent[intent]
"""Instead of using i as the outer layer key,
should we use some more specific like the key
Expand Down
2 changes: 1 addition & 1 deletion foreshadow/tests/test_core/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def test_resolver_overall():
columns = ["financials"]
data = pd.DataFrame({"financials": np.arange(100)}, columns=columns)
cs = ColumnSharer()
ir = IntentMapper(cs)
ir = IntentMapper(column_sharer=cs)
ir.fit(data)
assert cs["intent", "financials"] == "Numeric"
22 changes: 22 additions & 0 deletions foreshadow/tests/test_preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,25 @@ def test_data_preparer_fit(cleaner_kwargs):
cs = ColumnSharer()
dp = DataPreparer(cs, cleaner_kwargs=cleaner_kwargs)
dp.fit(data)


@pytest.mark.parametrize("deep", [True, False])
def test_data_preparer_get_params(deep):
"""Test thet get_params returns the minimum required.
Args:
deep: arg to get_params
"""
from foreshadow.preparer import DataPreparer

dp = DataPreparer()
params = dp.get_params(deep=deep)
assert "cleaner_kwargs" in params
assert "column_sharer" in params
assert "engineerer_kwargs" in params
assert "intent_kwargs" in params
assert "preprocessor_kwargs" in params
assert "reducer_kwargs" in params
assert "y_var" in params
assert "steps" in params

0 comments on commit 98fe73e

Please sign in to comment.