Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling return type when creating features from DatetimeTimeIndex #266

Merged
merged 8 commits into from Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions featuretools/primitives/aggregation_primitives.py
Expand Up @@ -83,7 +83,7 @@ def pd_mode(s):
Min = make_agg_primitive(
np.min,
[Numeric],
None,
Numeric,
name="Min",
stack_on_self=False,
description="Finds the minimum non-null value of a numeric feature.")
Expand All @@ -93,7 +93,7 @@ class Max(AggregationPrimitive):
"""Finds the maximum non-null value of a numeric feature."""
name = "max"
input_types = [Numeric]
return_type = None
return_type = Numeric
# max_stack_depth = 1
stack_on_self = False

Expand Down Expand Up @@ -222,7 +222,7 @@ class Median(AggregationPrimitive):
"""Finds the median value of any feature with well-ordered values."""
name = "median"
input_types = [Numeric]
return_type = None
return_type = Numeric
# max_stack_depth = 2

def get_function(self):
Expand Down
7 changes: 6 additions & 1 deletion featuretools/primitives/primitive_base.py
Expand Up @@ -11,7 +11,7 @@
_check_time_against_column,
_check_timedelta
)
from featuretools.variable_types import Variable
from featuretools.variable_types import Datetime, DatetimeTimeIndex, Variable

logger = logging.getLogger('featuretools')

Expand Down Expand Up @@ -101,6 +101,11 @@ def variable_type(self):
feature = feature.base_features[0]
return_type = feature.return_type

# only the original time index should exist
# so make this feature's return type just a Datetime
if return_type == DatetimeTimeIndex:
rwedge marked this conversation as resolved.
Show resolved Hide resolved
return_type = Datetime

return return_type

@property
Expand Down
19 changes: 18 additions & 1 deletion featuretools/tests/feature_function_tests/test_primitive_base.py
Expand Up @@ -2,8 +2,9 @@

from ..testing_utils import make_ecommerce_entityset

from featuretools.primitives import Feature, IdentityFeature, Last, Sum
from featuretools.primitives import Feature, IdentityFeature, Last, Mode, Sum
from featuretools.utils.gen_utils import getsize
from featuretools.variable_types import Datetime


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -79,3 +80,19 @@ def test_squared(es):
squared = feature * feature
assert len(squared.base_features) == 1
assert squared.base_features[0].hash() == feature.hash()


def test_return_type_inference(es):
mode = Mode(es["log"]["priority_level"], es["customers"])
assert mode.variable_type == es["log"]["priority_level"].__class__


def test_return_type_inference_direct_feature(es):
mode = Mode(es["log"]["priority_level"], es["customers"])
mode_session = Feature(mode, es["sessions"])
assert mode_session.variable_type == es["log"]["priority_level"].__class__


def test_return_type_inference_time_index(es):
last = Last(es["log"]["datetime"], es["customers"])
assert last.variable_type == Datetime