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, 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', (['"""ignore:the matrix subclass"""'], {}), False, 'import pytest\n'), (104, 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', (['"""ignore:Discarding near-constant"""'], {}), False, 'import pytest\n'), (39, 'pandas.DataFrame', 'pd.DataFrame', (['X_cont'], {'columns': 'cont_columns'}), True, 'import pandas as pd\n'), (57, 'dabl.preprocessing.detect_types', 'detect_types', (['X_clean'], {}), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), (59, 'numpy.all', 'np.all', (["(column_types[:continuous_features] == 'continuous')"], {}), True, 'import numpy as np\n'), (60, 'numpy.all', 'np.all', (["(column_types[continuous_features:-1] == 'categorical')"], {}), True, 'import numpy as np\n'), (66, 'dabl.plot.supervised.plot', 'plot', (['X_clean'], {'target_col': '"""target"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (67, 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), True, 'import matplotlib.pyplot as plt\n'), (24, 'itertools.product', 'itertools.product', (['[0, 1, 3, 100]', '[0, 1, 3, 100]', "['classification', 'regression']"], {}), False, 'import itertools\n'), (76, 'numpy.random.uniform', 'np.random.uniform', ([], {'size': '(100)'}), True, 'import numpy as np\n'), (77, 'dabl.plot.supervised.plot', 'plot', (['X'], {'type_hints': "{(0): feature_type, 'target': target_type}", 'target_col': '"""target"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (83, 'matplotlib.pyplot.gca', 'plt.gca', ([], {}), True, 'import matplotlib.pyplot as plt\n'), (87, 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), True, 'import matplotlib.pyplot as plt\n'), (71, 'itertools.product', 'itertools.product', (['[0, 0.1]', "['continuous', 'categorical']", "['continuous', 'categorical']"], {}), False, 'import itertools\n'), (92, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (93, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (95, 'dabl.preprocessing.detect_types', 'detect_types', (['data'], {}), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), (97, 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (100, 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""', 'type_hints': "{'target': 'categorical'}"}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (101, 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), True, 'import matplotlib.pyplot as plt\n'), (106, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (107, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (116, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (117, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (132, 'sklearn.datasets.load_digits', 'load_digits', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (133, 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', (['data'], {}), False, 'from dabl.utils import data_df_from_bunch\n'), (134, 'dabl.plot.supervised.plot', 'plot', (['df[::10]'], {'target_col': '"""target"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (138, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (139, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (140, 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (144, 'sklearn.datasets.make_regression', 'make_regression', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (145, 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (149, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {'centers': '(2)'}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (150, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (151, 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {'univariate_plot': '"""kde"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (155, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (156, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (158, 'dabl.plot.supervised.plot', 'plot', (['X'], {'target_col': '(3)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (168, 'dabl.preprocessing.guess_ordinal', 'guess_ordinal', (['data[0]'], {}), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), (170, 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '(1)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (180, 'sklearn.datasets.fetch_openml', 'fetch_openml', (['"""MiceProtein"""'], {}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (181, 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', (['data'], {}), False, 'from dabl.utils import data_df_from_bunch\n'), (183, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (190, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df.iloc[:, -7:]'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (197, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df.iloc[:, -6:]'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (205, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df'], {'target_col': '"""target"""', 'random_state': '(42)'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (239, 'sklearn.datasets.make_blobs', 'make_blobs', ([], {'n_samples': '(30)'}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (240, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (241, 'pandas.Series', 'pd.Series', (['y'], {}), True, 'import pandas as pd\n'), (246, 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (250, 'sklearn.datasets.load_diabetes', 'load_diabetes', ([], {'return_X_y': '(True)'}), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), (251, 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), True, 'import pandas as pd\n'), (290, 'dabl.plot.supervised.plot', 'plot', (['df'], {'target_col': '"""y"""'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (302, 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df'], {'target_col': 'b'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (307, 'dabl.set_config', 'set_config', ([], {'truncate_labels': '(False)'}), False, 'from dabl import set_config\n'), (308, 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df'], {'target_col': 'b'}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (312, 'dabl.set_config', 'set_config', ([], {'truncate_labels': '(True)'}), False, 'from dabl import set_config\n'), (44, 'pandas.concat', 'pd.concat', (['[df_cont, df_cat]'], {'axis': '(1)'}), True, 'import pandas as pd\n'), (51, 'numpy.random.uniform', 'np.random.uniform', ([], {'size': 'n_samples'}), True, 'import numpy as np\n'), (109, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""Less than two classes"""'}), False, 'import pytest\n'), (110, 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (111, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""Less than two classes"""'}), False, 'import pytest\n'), (112, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (119, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need continuous"""'}), False, 'import pytest\n'), (120, 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (121, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need continuous"""'}), False, 'import pytest\n'), (122, 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (125, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need categorical"""'}), False, 'import pytest\n'), (126, 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (127, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need categorical"""'}), False, 'import pytest\n'), (128, 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['X', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (254, 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), False, 'import pytest\n'), (256, 'dabl.plot.supervised.plot', 'plot', (['X', '"""target_col"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (257, 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), False, 'import pytest\n'), (259, 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['X', '"""target_col"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (260, 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), False, 'import pytest\n'), (262, 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', (['X', '"""target_col"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (276, 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Dropped 1 outliers in column target."""'}), False, 'import pytest\n'), (280, 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df', '"""target"""'], {}), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), (301, 'numpy.random.uniform', 'np.random.uniform', (['(0)', '(0.1)', '(1000)'], {}), True, 'import numpy as np\n'), (53, 'numpy.percentile', 'np.percentile', (['y', '[5, 10, 60, 85]'], {}), True, 'import numpy as np\n'), (75, 'numpy.random.randint', 'np.random.randint', (['(4)'], {'size': '(100)'}), True, 'import numpy as np\n'), (176, 'pandas.Series', 'pd.Series', (['[6786930208, 2142878625, 9106275431]'], {}), True, 'import pandas as pd\n'), (284, 'numpy.random.normal', 'np.random.normal', ([], {'size': '(300)'}), True, 'import numpy as np\n'), (300, 'numpy.random.uniform', 'np.random.uniform', (['(0)', '(1)', '(1000)'], {}), True, 'import numpy as np\n'), (37, 'sklearn.preprocessing.KBinsDiscretizer', 'KBinsDiscretizer', ([], {'encode': '"""ordinal"""'}), False, 'from sklearn.preprocessing import KBinsDiscretizer\n'), (42, 'pandas.DataFrame', 'pd.DataFrame', (['X_cat'], {'columns': 'cat_columns'}), True, 'import pandas as pd\n'), (81, 'matplotlib.pyplot.gcf', 'plt.gcf', ([], {}), True, 'import matplotlib.pyplot as plt\n'), (164, 'numpy.random.randint', 'np.random.randint', (['(0)', '(2)'], {'size': '(1000)'}), True, 'import numpy as np\n'), (268, 'numpy.random.randint', 'np.random.randint', ([], {'low': '(1)', 'high': '(100)', 'size': '(200)'}), True, 'import numpy as np\n'), (270, 'numpy.random.randint', 'np.random.randint', ([], {'low': '(50)', 'high': '(100)', 'size': '(200)'}), True, 'import numpy as np\n'), (163, 'numpy.random.randint', 'np.random.randint', (['(0)', '(10)'], {'size': '(1000)'}), True, 'import numpy as np\n'), (166, 'dabl.preprocessing.detect_types', 'detect_types', (['data'], {}), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n')]