Skip to content

Commit

Permalink
Empty dataframe data type error (#376) (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorisjlee authored May 18, 2021
1 parent c25ff79 commit 2db6964
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lux/executor/Executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def compute_data_type(self):

def mapping(self, rmap):
group_map = {}
if rmap == {}:
return {}
for val in ["quantitative", "id", "nominal", "temporal", "geographical"]:
group_map[val] = list(filter(lambda x: rmap[x] == val, rmap))
return group_map
Expand Down
2 changes: 0 additions & 2 deletions lux/processor/Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ def populate_data_type_model(ldf, vlist):
from lux.utils.date_utils import is_datetime_string

data_model_lookup = lux.config.executor.compute_data_model_lookup(ldf.data_type)

for vis in vlist:
for clause in vis._inferred_intent:
if clause.description == "?":
clause.description = ""
# TODO: Note that "and not is_datetime_string(clause.attribute))" is a temporary hack and breaks the `test_row_column_group` example
# and not is_datetime_string(clause.attribute):
if clause.attribute != "" and clause.attribute != "Record":
if clause.data_type == "":
clause.data_type = ldf.data_type[clause.attribute]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_nan.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ def test_numeric_with_nan():
# len(a.recommendation["Distribution"]) == 2
# ), "Example where dtype might be off after dropna(), check if histograms are still displayed"
assert "" in a._message.to_html(), "No warning message for NaN should be displayed"


def test_empty_filter(global_var):
df = pytest.car_df
df["Year"] = pd.to_datetime(df["Year"], format="%Y")
fdf = df[df["Origin"] == "U"]
fdf._ipython_display_()
assert fdf.data_type == None
assert len(df[df["Origin"] == "U"]) == 0

0 comments on commit 2db6964

Please sign in to comment.