import pytest
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import itertools

from sklearn.datasets import (make_regression, make_blobs, load_digits,
                              fetch_openml, load_diabetes)
from sklearn.preprocessing import KBinsDiscretizer
from dabl.preprocessing import clean, detect_types, guess_ordinal
from dabl.plot.supervised import (
    plot, plot_classification_categorical,
    plot_classification_continuous, plot_regression_categorical,
    plot_regression_continuous)
from dabl.utils import data_df_from_bunch
from dabl import set_config


# FIXME: check that target is not y but a column name

@pytest.mark.filterwarnings('ignore:the matrix subclass')
@pytest.mark.parametrize("continuous_features, categorical_features, task",
                         itertools.product([0, 1, 3, 100], [0, 1, 3, 100],
                                           ['classification', 'regression']))
def test_plots_smoke(continuous_features, categorical_features, task):
    # simple smoke test
    # should be parametrized
    n_samples = 100
    X_cont, y_cont = make_regression(
        n_samples=n_samples, n_features=continuous_features,
        n_informative=min(continuous_features, 2))
    X_cat, y_cat = make_regression(
        n_samples=n_samples, n_features=categorical_features,
        n_informative=min(categorical_features, 2))
    if X_cat.shape[1] > 0:
        X_cat = KBinsDiscretizer(encode='ordinal').fit_transform(X_cat)
    cont_columns = ["asdf_%d_cont" % i for i in range(continuous_features)]
    df_cont = pd.DataFrame(X_cont, columns=cont_columns)
    if categorical_features > 0:
        cat_columns = ["asdf_%d_cat" % i for i in range(categorical_features)]
        df_cat = pd.DataFrame(X_cat, columns=cat_columns).astype('int')
        df_cat = df_cat.astype("category")
        X_df = pd.concat([df_cont, df_cat], axis=1)
    else:
        X_df = df_cont
    assert(X_df.shape[1] == continuous_features + categorical_features)
    X_clean = clean(X_df.copy())
    y = y_cont + y_cat
    if X_df.shape[1] == 0:
        y = np.random.uniform(size=n_samples)
    if task == "classification":
        y = np.digitize(y, np.percentile(y, [5, 10, 60, 85]))
    X_clean['target'] = y
    if task == "classification":
        X_clean['target'] = X_clean['target'].astype('category')
    types = detect_types(X_clean)
    column_types = types.T.idxmax()
    assert np.all(column_types[:continuous_features] == 'continuous')
    assert np.all(column_types[continuous_features:-1] == 'categorical')
    if task == "classification":
        assert column_types[-1] == 'categorical'
    else:
        assert column_types[-1] == 'continuous'

    plot(X_clean, target_col='target')
    plt.close("all")


@pytest.mark.parametrize("add, feature_type, target_type",
                         itertools.product([0, .1],
                                           ['continuous', 'categorical'],
                                           ['continuous', 'categorical']))
def test_type_hints(add, feature_type, target_type):
    X = pd.DataFrame(np.random.randint(4, size=100)) + add
    X['target'] = np.random.uniform(size=100)
    plot(X, type_hints={0: feature_type,
                        'target': target_type},
         target_col='target')
    # get title of figure
    text = plt.gcf()._suptitle.get_text()
    assert feature_type.capitalize() in text
    ax = plt.gca()
    # one of the labels is 'target' iif regression
    labels = ax.get_ylabel() + ax.get_xlabel()
    assert ('target' in labels) == (target_type == 'continuous')
    plt.close("all")


def test_float_classification_target():
    # check we can plot even if we do classification with a float target
    X, y = make_blobs()
    data = pd.DataFrame(X)
    data['target'] = y.astype(np.float)
    types = detect_types(data)
    assert types.categorical['target']
    plot(data, target_col='target')
    # same with "actual float" - we need to specify classification for that :-/
    data['target'] = y.astype(np.float) + .2
    plot(data, target_col='target', type_hints={'target': 'categorical'})
    plt.close("all")


@pytest.mark.filterwarnings('ignore:Discarding near-constant')
def test_plot_classification_n_classes():
    X, y = make_blobs()
    X = pd.DataFrame(X)
    X['target'] = 0
    with pytest.raises(ValueError, match="Less than two classes"):
        plot_classification_categorical(X, 'target')
    with pytest.raises(ValueError, match="Less than two classes"):
        plot_classification_continuous(X, 'target')


def test_plot_wrong_target_type():
    X, y = make_blobs()
    X = pd.DataFrame(X)
    X['target'] = y
    with pytest.raises(ValueError, match="need continuous"):
        plot_regression_categorical(X, 'target')
    with pytest.raises(ValueError, match="need continuous"):
        plot_regression_continuous(X, 'target')

    X['target'] = X[0]
    with pytest.raises(ValueError, match="need categorical"):
        plot_classification_categorical(X, 'target')
    with pytest.raises(ValueError, match="need categorical"):
        plot_classification_continuous(X, 'target')


def test_plot_target_low_card_int():
    data = load_digits()
    df = data_df_from_bunch(data)
    plot(df[::10], target_col='target')


def test_plot_X_y():
    X, y = make_blobs()
    X = pd.DataFrame(X)
    plot(X, y)


def test_plot_regression_numpy():
    X, y = make_regression()
    plot(X, y)


def test_plot_lda_binary():
    X, y = make_blobs(centers=2)
    X = pd.DataFrame(X)
    plot(X, y, univariate_plot='kde')


def test_plot_int_column_name():
    X, y = make_blobs()
    X = pd.DataFrame(X)
    X[3] = y
    plot(X, target_col=3)


def test_negative_ordinal():
    # check that a low card int with negative values is plotted correctly
    data = pd.DataFrame([np.random.randint(0, 10, size=1000) - 5,
                         np.random.randint(0, 2, size=1000)]).T
    # ensure first column is low_card_int
    assert (detect_types(data).T.idxmax()
            == ['low_card_int', 'categorical']).all()
    assert guess_ordinal(data[0])
    # smoke test
    plot(data, target_col=1)


def test_large_ordinal():
    # check that large integers don't bring us down (bincount memory error)
    # here some random phone numbers
    assert not guess_ordinal(pd.Series([6786930208, 2142878625, 9106275431]))


def test_plot_classification_continuous():
    data = fetch_openml('MiceProtein')
    df = data_df_from_bunch(data)
    # only univariate plots
    figures = plot_classification_continuous(df, target_col='target',
                                             plot_pairwise=False)
    assert len(figures) == 1
    # top 10 axes
    assert len(figures[0].get_axes()) == 10
    # six is the minimum number of features for histograms
    # (last column is target)
    figures = plot_classification_continuous(df.iloc[:, -7:],
                                             target_col='target',
                                             plot_pairwise=False)
    assert len(figures) == 1
    assert len(figures[0].get_axes()) == 6

    # for 5 features, do full pairplot
    figures = plot_classification_continuous(df.iloc[:, -6:],
                                             target_col='target',
                                             plot_pairwise=False)
    assert len(figures) == 1
    # diagonal has twin axes
    assert len(figures[0].get_axes()) == 5 * 5 + 5

    # also do pairwise plots
    figures = plot_classification_continuous(df, target_col='target',
                                             random_state=42)
    # univariate, pairwise, pca, lda
    assert len(figures) == 4
    # univariate
    axes = figures[0].get_axes()
    assert len(axes) == 10
    # known result
    assert axes[0].get_xlabel() == "SOD1_N"
    # bar plot never has ylabel
    assert axes[0].get_ylabel() == ""
    # pairwise
    axes = figures[1].get_axes()
    assert len(axes) == 4
    # known result
    assert axes[0].get_xlabel() == "SOD1_N"
    assert axes[0].get_ylabel() == 'S6_N'

    # PCA
    axes = figures[2].get_axes()
    assert len(axes) == 4
    # known result
    assert axes[0].get_xlabel() == "PCA 1"
    assert axes[0].get_ylabel() == 'PCA 5'

    # LDA
    axes = figures[3].get_axes()
    assert len(axes) == 4
    # known result
    assert axes[0].get_xlabel() == "LDA 0"
    assert axes[0].get_ylabel() == 'LDA 1'


def test_plot_string_target():
    X, y = make_blobs(n_samples=30)
    data = pd.DataFrame(X)
    y = pd.Series(y)
    y[y == 0] = 'a'
    y[y == 1] = 'b'
    y[y == 2] = 'c'
    data['target'] = y
    plot(data, target_col='target')


def test_na_vals_reg_plot_raise_warning():
    X, y = load_diabetes(return_X_y=True)
    X = pd.DataFrame(X)
    y[::50] = np.NaN
    X['target_col'] = y
    with pytest.warns(UserWarning, match="Missing values in target_col have "
                                         "been removed for regression"):
        plot(X, 'target_col')
    with pytest.warns(UserWarning, match="Missing values in target_col have "
                                         "been removed for regression"):
        plot_regression_continuous(X, 'target_col')
    with pytest.warns(UserWarning, match="Missing values in target_col have "
                                         "been removed for regression"):
        plot_regression_categorical(X, 'target_col')


def test_plot_regression_continuous_with_target_outliers():
    df = pd.DataFrame(
        data={
            "feature": np.random.randint(low=1, high=100, size=200),
            # target values are bound between 50 and 100
            "target": np.random.randint(low=50, high=100, size=200)
            }
    )
    # append single outlier record with target value 0
    df = df.append({"feature": 50, "target": 0}, ignore_index=True)

    with pytest.warns(
        UserWarning,
        match="Dropped 1 outliers in column target."
    ):
        plot_regression_continuous(df, 'target')


def test_plot_regression_categorical_missing_value():
    df = pd.DataFrame({'y': np.random.normal(size=300)})
    df.loc[100:200, 'y'] += 1
    df.loc[200:300, 'y'] += 2
    df['x'] = 'a'
    df.loc[100:200, 'x'] = 'b'
    df.loc[200:300, 'x'] = np.NaN
    res = plot(df, target_col='y')
    assert len(res[1][0, 0].get_yticklabels()) == 3
    assert res[1][0, 0].get_yticklabels()[2].get_text() == 'dabl_mi...'


def test_label_truncation():
    a = ('a_really_long_name_that_would_mess_up_the_layout_a_lot'
         '_by_just_being_very_long')
    b = ('the_target_that_has_an_equally_long_name_which_would_'
         'mess_up_everything_as_well_but_in_different_places')
    df = pd.DataFrame({a: np.random.uniform(0, 1, 1000)})
    df[b] = df[a] + np.random.uniform(0, 0.1, 1000)
    res = plot_regression_continuous(df, target_col=b)

    assert res[0, 0].get_ylabel() == 'the_target_that_h...'
    assert res[0, 0].get_xlabel() == 'a_really_long_nam...'

    set_config(truncate_labels=False)
    res = plot_regression_continuous(df, target_col=b)

    assert res[0, 0].get_ylabel() == b
    assert res[0, 0].get_xlabel() == a
    set_config(truncate_labels=True)

[((22, 1, 22, 57), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', ({(22, 28, 22, 56): '"""ignore:the matrix subclass"""'}, {}), "('ignore:the matrix subclass')", False, 'import pytest\n'), ((104, 1, 104, 62), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', ({(104, 28, 104, 61): '"""ignore:Discarding near-constant"""'}, {}), "('ignore:Discarding near-constant')", False, 'import pytest\n'), ((39, 14, 39, 56), 'pandas.DataFrame', 'pd.DataFrame', (), '', True, 'import pandas as pd\n'), ((57, 12, 57, 33), 'dabl.preprocessing.detect_types', 'detect_types', ({(57, 25, 57, 32): 'X_clean'}, {}), '(X_clean)', False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((59, 11, 59, 69), 'numpy.all', 'np.all', ({(59, 18, 59, 68): "(column_types[:continuous_features] == 'continuous')"}, {}), "(column_types[:continuous_features] == 'continuous')", True, 'import numpy as np\n'), ((60, 11, 60, 72), 'numpy.all', 'np.all', ({(60, 18, 60, 71): "(column_types[continuous_features:-1] == 'categorical')"}, {}), "(column_types[continuous_features:-1] == 'categorical')", True, 'import numpy as np\n'), ((66, 4, 66, 38), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((67, 4, 67, 20), 'matplotlib.pyplot.close', 'plt.close', ({(67, 14, 67, 19): '"""all"""'}, {}), "('all')", True, 'import matplotlib.pyplot as plt\n'), ((24, 25, 25, 76), 'itertools.product', 'itertools.product', ({(24, 43, 24, 57): '[0, 1, 3, 100]', (24, 59, 24, 73): '[0, 1, 3, 100]', (25, 43, 25, 75): "['classification', 'regression']"}, {}), "([0, 1, 3, 100], [0, 1, 3, 100], ['classification',\n    'regression'])", False, 'import itertools\n'), ((76, 18, 76, 45), 'numpy.random.uniform', 'np.random.uniform', (), '', True, 'import numpy as np\n'), ((77, 4, 79, 29), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((83, 9, 83, 18), 'matplotlib.pyplot.gca', 'plt.gca', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((87, 4, 87, 20), 'matplotlib.pyplot.close', 'plt.close', ({(87, 14, 87, 19): '"""all"""'}, {}), "('all')", True, 'import matplotlib.pyplot as plt\n'), ((71, 25, 73, 73), 'itertools.product', 'itertools.product', ({(71, 43, 71, 50): '[0, 0.1]', (72, 43, 72, 72): "['continuous', 'categorical']", (73, 43, 73, 72): "['continuous', 'categorical']"}, {}), "([0, 0.1], ['continuous', 'categorical'], ['continuous',\n    'categorical'])", False, 'import itertools\n'), ((92, 11, 92, 23), 'sklearn.datasets.make_blobs', 'make_blobs', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((93, 11, 93, 26), 'pandas.DataFrame', 'pd.DataFrame', ({(93, 24, 93, 25): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((95, 12, 95, 30), 'dabl.preprocessing.detect_types', 'detect_types', ({(95, 25, 95, 29): 'data'}, {}), '(data)', False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((97, 4, 97, 35), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((100, 4, 100, 73), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((101, 4, 101, 20), 'matplotlib.pyplot.close', 'plt.close', ({(101, 14, 101, 19): '"""all"""'}, {}), "('all')", True, 'import matplotlib.pyplot as plt\n'), ((106, 11, 106, 23), 'sklearn.datasets.make_blobs', 'make_blobs', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((107, 8, 107, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(107, 21, 107, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((116, 11, 116, 23), 'sklearn.datasets.make_blobs', 'make_blobs', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((117, 8, 117, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(117, 21, 117, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((132, 11, 132, 24), 'sklearn.datasets.load_digits', 'load_digits', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((133, 9, 133, 33), 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', ({(133, 28, 133, 32): 'data'}, {}), '(data)', False, 'from dabl.utils import data_df_from_bunch\n'), ((134, 4, 134, 39), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((138, 11, 138, 23), 'sklearn.datasets.make_blobs', 'make_blobs', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((139, 8, 139, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(139, 21, 139, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((140, 4, 140, 14), 'dabl.plot.supervised.plot', 'plot', ({(140, 9, 140, 10): 'X', (140, 12, 140, 13): 'y'}, {}), '(X, y)', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((144, 11, 144, 28), 'sklearn.datasets.make_regression', 'make_regression', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((145, 4, 145, 14), 'dabl.plot.supervised.plot', 'plot', ({(145, 9, 145, 10): 'X', (145, 12, 145, 13): 'y'}, {}), '(X, y)', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((149, 11, 149, 32), 'sklearn.datasets.make_blobs', 'make_blobs', (), '', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((150, 8, 150, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(150, 21, 150, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((151, 4, 151, 37), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((155, 11, 155, 23), 'sklearn.datasets.make_blobs', 'make_blobs', ({}, {}), '()', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((156, 8, 156, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(156, 21, 156, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((158, 4, 158, 25), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((168, 11, 168, 33), 'dabl.preprocessing.guess_ordinal', 'guess_ordinal', ({(168, 25, 168, 32): 'data[0]'}, {}), '(data[0])', False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((170, 4, 170, 28), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((180, 11, 180, 38), 'sklearn.datasets.fetch_openml', 'fetch_openml', ({(180, 24, 180, 37): '"""MiceProtein"""'}, {}), "('MiceProtein')", False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((181, 9, 181, 33), 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', ({(181, 28, 181, 32): 'data'}, {}), '(data)', False, 'from dabl.utils import data_df_from_bunch\n'), ((183, 14, 184, 65), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((190, 14, 192, 65), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((197, 14, 199, 65), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((205, 14, 206, 61), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((239, 11, 239, 35), 'sklearn.datasets.make_blobs', 'make_blobs', (), '', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((240, 11, 240, 26), 'pandas.DataFrame', 'pd.DataFrame', ({(240, 24, 240, 25): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((241, 8, 241, 20), 'pandas.Series', 'pd.Series', ({(241, 18, 241, 19): 'y'}, {}), '(y)', True, 'import pandas as pd\n'), ((246, 4, 246, 35), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((250, 11, 250, 41), 'sklearn.datasets.load_diabetes', 'load_diabetes', (), '', False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((251, 8, 251, 23), 'pandas.DataFrame', 'pd.DataFrame', ({(251, 21, 251, 22): 'X'}, {}), '(X)', True, 'import pandas as pd\n'), ((290, 10, 290, 34), 'dabl.plot.supervised.plot', 'plot', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((302, 10, 302, 54), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((307, 4, 307, 37), 'dabl.set_config', 'set_config', (), '', False, 'from dabl import set_config\n'), ((308, 10, 308, 54), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (), '', False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((312, 4, 312, 36), 'dabl.set_config', 'set_config', (), '', False, 'from dabl import set_config\n'), ((44, 15, 44, 51), 'pandas.concat', 'pd.concat', (), '', True, 'import pandas as pd\n'), ((51, 12, 51, 45), 'numpy.random.uniform', 'np.random.uniform', (), '', True, 'import numpy as np\n'), ((109, 9, 109, 65), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((110, 8, 110, 52), 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', ({(110, 40, 110, 41): 'X', (110, 43, 110, 51): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((111, 9, 111, 65), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((112, 8, 112, 51), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', ({(112, 39, 112, 40): 'X', (112, 42, 112, 50): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((119, 9, 119, 59), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((120, 8, 120, 48), 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', ({(120, 36, 120, 37): 'X', (120, 39, 120, 47): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((121, 9, 121, 59), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((122, 8, 122, 47), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', ({(122, 35, 122, 36): 'X', (122, 38, 122, 46): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((125, 9, 125, 60), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((126, 8, 126, 52), 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', ({(126, 40, 126, 41): 'X', (126, 43, 126, 51): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((127, 9, 127, 60), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((128, 8, 128, 51), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', ({(128, 39, 128, 40): 'X', (128, 42, 128, 50): '"""target"""'}, {}), "(X, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((254, 9, 255, 71), 'pytest.warns', 'pytest.warns', (), '', False, 'import pytest\n'), ((256, 8, 256, 29), 'dabl.plot.supervised.plot', 'plot', ({(256, 13, 256, 14): 'X', (256, 16, 256, 28): '"""target_col"""'}, {}), "(X, 'target_col')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((257, 9, 258, 71), 'pytest.warns', 'pytest.warns', (), '', False, 'import pytest\n'), ((259, 8, 259, 51), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', ({(259, 35, 259, 36): 'X', (259, 38, 259, 50): '"""target_col"""'}, {}), "(X, 'target_col')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((260, 9, 261, 71), 'pytest.warns', 'pytest.warns', (), '', False, 'import pytest\n'), ((262, 8, 262, 52), 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', ({(262, 36, 262, 37): 'X', (262, 39, 262, 51): '"""target_col"""'}, {}), "(X, 'target_col')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((276, 9, 279, 5), 'pytest.warns', 'pytest.warns', (), '', False, 'import pytest\n'), ((280, 8, 280, 48), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', ({(280, 35, 280, 37): 'df', (280, 39, 280, 47): '"""target"""'}, {}), "(df, 'target')", False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((301, 20, 301, 51), 'numpy.random.uniform', 'np.random.uniform', ({(301, 38, 301, 39): '(0)', (301, 41, 301, 44): '(0.1)', (301, 46, 301, 50): '(1000)'}, {}), '(0, 0.1, 1000)', True, 'import numpy as np\n'), ((53, 27, 53, 60), 'numpy.percentile', 'np.percentile', ({(53, 41, 53, 42): 'y', (53, 44, 53, 59): '[5, 10, 60, 85]'}, {}), '(y, [5, 10, 60, 85])', True, 'import numpy as np\n'), ((75, 21, 75, 51), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((176, 29, 176, 76), 'pandas.Series', 'pd.Series', ({(176, 39, 176, 75): '[6786930208, 2142878625, 9106275431]'}, {}), '([6786930208, 2142878625, 9106275431])', True, 'import pandas as pd\n'), ((284, 28, 284, 54), 'numpy.random.normal', 'np.random.normal', (), '', True, 'import numpy as np\n'), ((300, 26, 300, 55), 'numpy.random.uniform', 'np.random.uniform', ({(300, 44, 300, 45): '0', (300, 47, 300, 48): '1', (300, 50, 300, 54): '1000'}, {}), '(0, 1, 1000)', True, 'import numpy as np\n'), ((37, 16, 37, 50), 'sklearn.preprocessing.KBinsDiscretizer', 'KBinsDiscretizer', (), '', False, 'from sklearn.preprocessing import KBinsDiscretizer\n'), ((42, 17, 42, 57), 'pandas.DataFrame', 'pd.DataFrame', (), '', True, 'import pandas as pd\n'), ((81, 11, 81, 20), 'matplotlib.pyplot.gcf', 'plt.gcf', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((164, 25, 164, 59), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((268, 23, 268, 67), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((270, 22, 270, 67), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((163, 25, 163, 60), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((166, 12, 166, 30), 'dabl.preprocessing.detect_types', 'detect_types', ({(166, 25, 166, 29): 'data'}, {}), '(data)', False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n')]