Skip to content

Commit

Permalink
Add doctests to setup.cfg (#491)
Browse files Browse the repository at this point in the history
* Update setup.cfg

* fix docstests

* remove test, fix Min

* fix lint

* fix tests

* remove comment
  • Loading branch information
gsheni committed Apr 12, 2019
1 parent 62df835 commit d58cdce
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
5 changes: 3 additions & 2 deletions featuretools/entityset/entity.py
Expand Up @@ -202,8 +202,9 @@ def convert_variable_type(self, variable_id, new_type,
RuntimeError : Raises if it cannot convert the underlying data
Examples:
>>> es["customer"].convert_variable_type("education_level", vtypes.Categorical, EntitySet)
True
>>> from featuretools.tests.testing_utils import make_ecommerce_entityset
>>> es = make_ecommerce_entityset()
>>> es["customers"].convert_variable_type("engagement_level", vtypes.Categorical)
"""
if convert_data:
# first, convert the underlying data (or at least try to)
Expand Down
4 changes: 0 additions & 4 deletions featuretools/entityset/entityset.py
Expand Up @@ -123,10 +123,6 @@ def __getitem__(self, entity_id):
Returns:
:class:`.Entity` : Instance of entity. None if entity doesn't
exist.
Example:
>>> my_entityset[entity_id]
<Entity: id>
"""
if entity_id in self.entity_dict:
return self.entity_dict[entity_id]
Expand Down
7 changes: 5 additions & 2 deletions featuretools/entityset/timedelta.py
Expand Up @@ -30,8 +30,11 @@ class Timedelta(object):
For observation timedeltas, a
>>> Timedelta(10, "s") # 10 seconds
>>> Timedelta(3, "observations", entity='log') # 3 observations of the log entity
>>> Timedelta(10, "s").value_in_seconds # 10 seconds
10.0
>>> three_observations_log = Timedelta(3, "observations", entity='log')
>>> three_observations_log.get_name()
'3 Observations'
"""

_Observations = "o"
Expand Down
1 change: 1 addition & 0 deletions featuretools/primitives/api.py
@@ -1,4 +1,5 @@
# flake8: noqa
from .base import make_agg_primitive, make_trans_primitive
from .standard import *
from .utils import (
get_aggregation_primitives,
Expand Down
31 changes: 20 additions & 11 deletions featuretools/primitives/standard/aggregation_primitives.py
Expand Up @@ -5,10 +5,7 @@
import numpy as np
import pandas as pd

from ..base.aggregation_primitive_base import (
AggregationPrimitive,
make_agg_primitive
)
from ..base.aggregation_primitive_base import AggregationPrimitive

from featuretools.variable_types import (
Boolean,
Expand Down Expand Up @@ -97,13 +94,25 @@ def pd_mode(s):
return pd_mode


Min = make_agg_primitive(
np.min,
[Numeric],
Numeric,
name="Min",
stack_on_self=False,
description="Finds the minimum non-null value of a numeric feature.")
class Min(AggregationPrimitive):
"""Finds the minimum value of a numeric feature.
Description:
Given a list of values, return the minimum value.
Ignores `NaN` values.
Examples:
>>> min = Min()
>>> min([1, 2, 3, 4, 5, None])
1.0
"""
name = "min"
input_types = [Numeric]
return_type = Numeric
stack_on_self = False

def get_function(self):
return np.min


class Max(AggregationPrimitive):
Expand Down
24 changes: 11 additions & 13 deletions featuretools/primitives/standard/transform_primitive.py
Expand Up @@ -5,10 +5,7 @@
import numpy as np
import pandas as pd

from ..base.transform_primitive_base import (
TransformPrimitive,
make_trans_primitive
)
from ..base.transform_primitive_base import TransformPrimitive

from featuretools.variable_types import (
Boolean,
Expand Down Expand Up @@ -196,17 +193,18 @@ def word_counter(array):
return word_counter


def pd_time_since(array, time):
class TimeSince(TransformPrimitive):
"""Calculates time since the cutoff time."""
return (time - pd.DatetimeIndex(array)).values

name = 'time_since'
input_types = [[DatetimeTimeIndex], [Datetime]]
return_type = Timedelta
uses_calc_time = True

TimeSince = make_trans_primitive(function=pd_time_since,
input_types=[[DatetimeTimeIndex], [Datetime]],
return_type=Timedelta,
uses_calc_time=True,
description="Calculates time since the cutoff time.",
name="time_since")
def get_function(self):
def pd_time_since(array, time):
"""Calculates time since the cutoff time."""
return (time - pd.DatetimeIndex(array)).values
return pd_time_since


class DaysSince(TransformPrimitive):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -3,7 +3,7 @@ description-file = README.md
[aliases]
test=pytest
[tool:pytest]
addopts = -m "not requires_training_data and not requires_credentials" --ignore "featuretools/tests/primitive_tests/primitives_to_install/featuretools_pip_tester/"
addopts = -m "not requires_training_data and not requires_credentials" --ignore "featuretools/tests/primitive_tests/primitives_to_install/featuretools_pip_tester/" --doctest-modules
python_files = featuretools/tests/*
filterwarnings =
ignore::DeprecationWarning
Expand Down

0 comments on commit d58cdce

Please sign in to comment.