def test_interestingness_1_2_0(global_var): from lux.vis.Vis import Vis from lux.vis.Vis import Clause from lux.interestingness.interestingness import interestingness df = pytest.car_df y_clause = Clause(attribute="Name", channel="y") color_clause = Clause(attribute="Cylinders", channel="color") new_vis = Vis([y_clause, color_clause]) new_vis.refresh_source(df) new_vis # assert(len(new_vis.data)==color_cardinality*group_by_cardinality) assert interestingness(new_vis, df) < 0.01
def test_interestingness_1_2_0(): from lux.vis.Vis import Vis from lux.vis.Vis import Clause from lux.interestingness.interestingness import interestingness df = pd.read_csv("lux/data/car.csv") y_clause = Clause(attribute = "Name", channel = "y") color_clause = Clause(attribute = 'Cylinders', channel = "color") new_vis = Vis([y_clause, color_clause]) new_vis.refresh_source(df) new_vis #assert(len(new_vis.data)==color_cardinality*group_by_cardinality) assert(interestingness(new_vis, df)<0.01)
def test_refresh_inplace(): df = pd.DataFrame({ 'date': ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'], 'value': [10.5, 15.2, 20.3, 25.2] }) assert df.data_type['nominal'][0] == 'date' from lux.vis.Vis import Vis vis = Vis(["date", "value"], df) df['date'] = pd.to_datetime(df['date'], format="%Y-%m-%d") assert df.data_type['temporal'][0] == 'date' vis.refresh_source(df) assert vis.mark == "line" assert vis.get_attr_by_channel("x")[0].attribute == "date" assert vis.get_attr_by_channel("y")[0].attribute == "value"
def test_colored_bar_chart(): from lux.vis.Vis import Vis from lux.vis.Vis import Clause df = pd.read_csv("lux/data/car.csv") x_clause = Clause(attribute="MilesPerGal", channel="x") y_clause = Clause(attribute="Origin", channel="y") color_clause = Clause(attribute='Cylinders', channel="color") new_vis = Vis([x_clause, y_clause, color_clause]) new_vis.refresh_source(df) #make sure dimention of the data is correct color_cardinality = len(df.unique_values['Cylinders']) group_by_cardinality = len(df.unique_values['Origin']) assert (len(new_vis.data.columns) == 3) assert ( len(new_vis.data) == 15 > group_by_cardinality < color_cardinality * group_by_cardinality ) # Not color_cardinality*group_by_cardinality since some combinations have 0 values
def test_colored_line_chart(): from lux.vis.Vis import Vis from lux.vis.Vis import Clause df = pd.read_csv("lux/data/car.csv") df["Year"] = pd.to_datetime( df["Year"], format='%Y') # change pandas dtype for the column "Year" to datetype x_clause = Clause(attribute="Year", channel="x") y_clause = Clause(attribute="MilesPerGal", channel="y") color_clause = Clause(attribute='Cylinders', channel="color") new_vis = Vis([x_clause, y_clause, color_clause]) new_vis.refresh_source(df) #make sure dimention of the data is correct color_cardinality = len(df.unique_values['Cylinders']) group_by_cardinality = len(df.unique_values['Year']) assert (len(new_vis.data.columns) == 3) assert ( len(new_vis.data) == 60 > group_by_cardinality < color_cardinality * group_by_cardinality ) # Not color_cardinality*group_by_cardinality since some combinations have 0 values
def test_refresh_inplace(): df = pd.DataFrame({ 'date': ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'], 'value': [10.5, 15.2, 20.3, 25.2] }) with pytest.warns( UserWarning, match="Lux detects that the attribute 'date' may be temporal."): df._repr_html_() assert df.data_type_lookup["date"] == "temporal" from lux.vis.Vis import Vis vis = Vis(["date", "value"], df) df['date'] = pd.to_datetime(df['date'], format="%Y-%m-%d") df.maintain_metadata() assert df.data_type['temporal'][0] == 'date' vis.refresh_source(df) assert vis.mark == "line" assert vis.get_attr_by_channel("x")[0].attribute == "date" assert vis.get_attr_by_channel("y")[0].attribute == "value"
def test_refresh_inplace(): df = pd.DataFrame( { "date": ["2020-01-01", "2020-02-01", "2020-03-01", "2020-04-01"], "value": [10.5, 15.2, 20.3, 25.2], } ) with pytest.warns(UserWarning, match="Lux detects that the attribute 'date' may be temporal."): df._ipython_display_() assert df.data_type["date"] == "temporal" from lux.vis.Vis import Vis vis = Vis(["date", "value"], df) df["date"] = pd.to_datetime(df["date"], format="%Y-%m-%d") df.maintain_metadata() inverted_data_type = lux.config.executor.invert_data_type(df.data_type) assert inverted_data_type["temporal"][0] == "date" vis.refresh_source(df) assert vis.mark == "line" assert vis.get_attr_by_channel("x")[0].attribute == "date" assert vis.get_attr_by_channel("y")[0].attribute == "value"