Skip to content

Commit

Permalink
move code to create_variables and add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
thehomebrewnerd committed Jun 2, 2020
1 parent 5cc780d commit 9f39593
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions featuretools/entityset/entity.py
Expand Up @@ -83,11 +83,6 @@ def __init__(self, id, df, entityset, variable_types=None,

self.set_secondary_time_index(secondary_time_index)

# Fill in single `NaN` values in LatLong variables with a tuple
latlongs = [k for k, v in self.variable_types.items() if v == vtypes.LatLong]
for latlong in latlongs:
self.df[latlong] = replace_latlong_nan(self.df[latlong])

def __repr__(self):
repr_out = u"Entity: {}\n".format(self.id)
repr_out += u" Variables:"
Expand Down Expand Up @@ -299,6 +294,11 @@ def _create_variables(self, variable_types, index, time_index, secondary_time_in
variable_types[vid] = string_to_class_map['unknown']
warnings.warn("Variable type {} was unrecognized, Unknown variable type was used instead".format(vtype))

# Fill in any single `NaN` values in LatLong variables with a tuple
if variable_types[vid] == vtypes.LatLong and self.df[vid].hasnans:
self.df[vid] = replace_latlong_nan(self.df[vid])
warnings.warn("All single `NaN` values in column `{}` have been replaced with `(NaN, NaN)`".format(vid))

if index not in variable_types:
variable_types[index] = vtypes.Index

Expand Down
4 changes: 3 additions & 1 deletion featuretools/tests/entityset_tests/test_entity.py
Expand Up @@ -229,5 +229,7 @@ def test_replace_latlong_nan_during_entity_creation(es):
nan_es = ft.EntitySet("latlong_nan")
df = es['log'].df.copy()
df['latlong'][0] = np.nan
entity = ft.Entity(id="nan_latlong_entity", df=df, entityset=nan_es, variable_types=es['log'].variable_types)

with pytest.warns(UserWarning, match="All single `NaN` values in column `latlong` have been replaced with `\\(NaN, NaN\\)`"):
entity = ft.Entity(id="nan_latlong_entity", df=df, entityset=nan_es, variable_types=es['log'].variable_types)
assert entity.df['latlong'][0] == (np.nan, np.nan)

0 comments on commit 9f39593

Please sign in to comment.