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

Replace infs with nans to avoid crash when creating a heatmap #442

Merged
merged 4 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lux/executor/PandasExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def execute_binning(ldf: LuxDataFrame, vis: Vis):
"""
import numpy as np

vis._vis_data = vis._vis_data.replace([np.inf, -np.inf], np.nan)

bin_attribute = [x for x in vis._inferred_intent if x.bin_size != 0][0]
bin_attr = bin_attribute.attribute
series = vis.data[bin_attr]
Expand Down Expand Up @@ -379,6 +381,10 @@ def execute_2D_binning(vis: Vis) -> None:
----------
vis : Vis
"""
import numpy as np

vis._vis_data = vis._vis_data.replace([np.inf, -np.inf], np.nan)

pd.reset_option("mode.chained_assignment")
with pd.option_context("mode.chained_assignment", None):
x_attr = vis.get_attr_by_channel("x")[0].attribute
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .context import lux
import pytest
import pandas as pd
import numpy as np


def test_head_tail(global_var):
Expand Down Expand Up @@ -54,3 +55,21 @@ def test_convert_dtype(global_var):
cdf = df.convert_dtypes()
cdf._ipython_display_()
assert list(cdf.recommendation.keys()) == ["Correlation", "Distribution", "Occurrence"]


def test_infs():
nrows = 100_000

# continuous
c1 = np.random.uniform(0, 1, size=nrows)
c1[2] = np.inf
c2 = np.random.uniform(0, 1, size=nrows)
c2[3] = np.inf

# discrete
d1 = np.random.randint(0, 2, size=nrows)
d2 = np.random.randint(0, 2, size=nrows)

df = pd.DataFrame({"c1": c1, "c2": c2, "d1": d1, "d2": d2})

df._ipython_display_()