def test_pairwise_density_plot_not_numeric(artworks_df, artworks_summary): plt.cla() def mock_render(fig): assert False explorer = Explorer(artworks_summary, plot_renderer=mock_render) with pytest.raises(ValueError): explorer.pairwise_density_plot("Diameter (cm)", "Nationality")
def test_pairwise_density_plot_both_categorical(artworks_df, artworks_summary): plt.cla() def mock_render(fig): # currently pairwise_density_plot returns a plotly figure assert len(fig["data"]) == 1 data = fig["data"][0] assert data["type"] == "heatmap" explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.pairwise_density_plot("Nationality", "Gender")
def test_pairwise_density_plot(artworks_df, artworks_summary): plt.cla() def mock_render(fig): # currently pairwise_density_plot returns a plotly figure assert len(fig['data']) == 1 data = fig['data'][0] assert data['type'] == 'heatmap' explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.pairwise_density_plot('Width (cm)', 'Height (cm)')
def test_correlation_plot_include(artworks_df, artworks_summary): plt.cla() def mock_render(fig): assert len(fig['data']) == 1 data = fig['data'][0] assert data['type'] == 'heatmap' assert set(data['y']) == set(data['x']) == {'Height (cm)'} explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.correlation_plot(include=['Height (cm)'])
def test_pairwise_density_plot_both_categorical(artworks_df, artworks_summary): plt.cla() def mock_render(fig): # currently pairwise_density_plot returns a plotly figure assert len(fig['data']) == 1 data = fig['data'][0] assert data['type'] == 'heatmap' explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.pairwise_density_plot('Nationality', 'Gender')
def test_correlation_plot_exclude(artworks_df, artworks_summary): plt.cla() def mock_render(fig): assert len(fig['data']) == 1 data = fig['data'][0] assert data['type'] == 'heatmap' expected_columns = {'Height (cm)', 'Depth (cm)'} assert set(data['y']) == set(data['x']) == expected_columns explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.correlation_plot(exclude=['Width (cm)'])
def test_correlation_plot_annotations(artworks_df, artworks_summary): plt.cla() def mock_render(fig): assert len(fig["data"]) == 1 corr = [item for row in fig["data"][0]["z"] for item in row] labels = [l["text"] for l in fig["layout"]["annotations"]] for c, l in zip(corr, labels): assert "{:.2g}".format(c) == l explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.correlation_plot( include=["Height (cm)", "Width (cm)", "Depth (cm)"]) explorer.correlation_plot(include=["Height (cm)", "Width (cm)"])
def test_correlation_plot_annotations(artworks_df, artworks_summary): plt.cla() def mock_render(fig): assert len(fig['data']) == 1 corr = [item for row in fig['data'][0]['z'] for item in row] labels = [l['text'] for l in fig['layout']['annotations']] for c, l in zip(corr, labels): assert '{:.2g}'.format(c) == l explorer = Explorer(artworks_summary, plot_renderer=mock_render) explorer.correlation_plot(include=['Height (cm)', 'Width (cm)', 'Depth (cm)']) explorer.correlation_plot(include=['Height (cm)', 'Width (cm)'])