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)

[((655, 711), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', (['"""ignore:the matrix subclass"""'], {}), "('ignore:the matrix subclass')\n", (681, 711), False, 'import pytest\n'), ((4153, 4214), 'pytest.mark.filterwarnings', 'pytest.mark.filterwarnings', (['"""ignore:Discarding near-constant"""'], {}), "('ignore:Discarding near-constant')\n", (4179, 4214), False, 'import pytest\n'), ((1574, 1616), 'pandas.DataFrame', 'pd.DataFrame', (['X_cont'], {'columns': 'cont_columns'}), '(X_cont, columns=cont_columns)\n', (1586, 1616), True, 'import pandas as pd\n'), ((2361, 2382), 'dabl.preprocessing.detect_types', 'detect_types', (['X_clean'], {}), '(X_clean)\n', (2373, 2382), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((2430, 2488), 'numpy.all', 'np.all', (["(column_types[:continuous_features] == 'continuous')"], {}), "(column_types[:continuous_features] == 'continuous')\n", (2436, 2488), True, 'import numpy as np\n'), ((2500, 2561), 'numpy.all', 'np.all', (["(column_types[continuous_features:-1] == 'categorical')"], {}), "(column_types[continuous_features:-1] == 'categorical')\n", (2506, 2561), True, 'import numpy as np\n'), ((2707, 2741), 'dabl.plot.supervised.plot', 'plot', (['X_clean'], {'target_col': '"""target"""'}), "(X_clean, target_col='target')\n", (2711, 2741), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((2746, 2762), 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), "('all')\n", (2755, 2762), True, 'import matplotlib.pyplot as plt\n'), ((813, 900), 'itertools.product', 'itertools.product', (['[0, 1, 3, 100]', '[0, 1, 3, 100]', "['classification', 'regression']"], {}), "([0, 1, 3, 100], [0, 1, 3, 100], ['classification',\n    'regression'])\n", (830, 900), False, 'import itertools\n'), ((3155, 3182), 'numpy.random.uniform', 'np.random.uniform', ([], {'size': '(100)'}), '(size=100)\n', (3172, 3182), True, 'import numpy as np\n'), ((3187, 3275), 'dabl.plot.supervised.plot', 'plot', (['X'], {'type_hints': "{(0): feature_type, 'target': target_type}", 'target_col': '"""target"""'}), "(X, type_hints={(0): feature_type, 'target': target_type}, target_col=\n    'target')\n", (3191, 3275), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((3424, 3433), 'matplotlib.pyplot.gca', 'plt.gca', ([], {}), '()\n', (3431, 3433), True, 'import matplotlib.pyplot as plt\n'), ((3601, 3617), 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), "('all')\n", (3610, 3617), True, 'import matplotlib.pyplot as plt\n'), ((2849, 2942), 'itertools.product', 'itertools.product', (['[0, 0.1]', "['continuous', 'categorical']", "['continuous', 'categorical']"], {}), "([0, 0.1], ['continuous', 'categorical'], ['continuous',\n    'categorical'])\n", (2866, 2942), False, 'import itertools\n'), ((3744, 3756), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), '()\n', (3754, 3756), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((3768, 3783), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (3780, 3783), True, 'import pandas as pd\n'), ((3836, 3854), 'dabl.preprocessing.detect_types', 'detect_types', (['data'], {}), '(data)\n', (3848, 3854), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((3898, 3929), 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""'}), "(data, target_col='target')\n", (3902, 3929), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4059, 4128), 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""', 'type_hints': "{'target': 'categorical'}"}), "(data, target_col='target', type_hints={'target': 'categorical'})\n", (4063, 4128), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4133, 4149), 'matplotlib.pyplot.close', 'plt.close', (['"""all"""'], {}), "('all')\n", (4142, 4149), True, 'import matplotlib.pyplot as plt\n'), ((4268, 4280), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), '()\n', (4278, 4280), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((4289, 4304), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (4301, 4304), True, 'import pandas as pd\n'), ((4612, 4624), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), '()\n', (4622, 4624), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((4633, 4648), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (4645, 4648), True, 'import pandas as pd\n'), ((5191, 5204), 'sklearn.datasets.load_digits', 'load_digits', ([], {}), '()\n', (5202, 5204), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((5214, 5238), 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', (['data'], {}), '(data)\n', (5232, 5238), False, 'from dabl.utils import data_df_from_bunch\n'), ((5243, 5278), 'dabl.plot.supervised.plot', 'plot', (['df[::10]'], {'target_col': '"""target"""'}), "(df[::10], target_col='target')\n", (5247, 5278), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((5313, 5325), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), '()\n', (5323, 5325), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((5334, 5349), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (5346, 5349), True, 'import pandas as pd\n'), ((5354, 5364), 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {}), '(X, y)\n', (5358, 5364), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((5412, 5429), 'sklearn.datasets.make_regression', 'make_regression', ([], {}), '()\n', (5427, 5429), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((5434, 5444), 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {}), '(X, y)\n', (5438, 5444), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((5486, 5507), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {'centers': '(2)'}), '(centers=2)\n', (5496, 5507), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((5516, 5531), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (5528, 5531), True, 'import pandas as pd\n'), ((5536, 5569), 'dabl.plot.supervised.plot', 'plot', (['X', 'y'], {'univariate_plot': '"""kde"""'}), "(X, y, univariate_plot='kde')\n", (5540, 5569), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((5616, 5628), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {}), '()\n', (5626, 5628), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((5637, 5652), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (5649, 5652), True, 'import pandas as pd\n'), ((5670, 5691), 'dabl.plot.supervised.plot', 'plot', (['X'], {'target_col': '(3)'}), '(X, target_col=3)\n', (5674, 5691), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((6076, 6098), 'dabl.preprocessing.guess_ordinal', 'guess_ordinal', (['data[0]'], {}), '(data[0])\n', (6089, 6098), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n'), ((6120, 6144), 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '(1)'}), '(data, target_col=1)\n', (6124, 6144), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((6420, 6447), 'sklearn.datasets.fetch_openml', 'fetch_openml', (['"""MiceProtein"""'], {}), "('MiceProtein')\n", (6432, 6447), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((6457, 6481), 'dabl.utils.data_df_from_bunch', 'data_df_from_bunch', (['data'], {}), '(data)\n', (6475, 6481), False, 'from dabl.utils import data_df_from_bunch\n'), ((6524, 6600), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), "(df, target_col='target', plot_pairwise=False)\n", (6554, 6600), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((6840, 6933), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df.iloc[:, -7:]'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), "(df.iloc[:, -7:], target_col='target',\n    plot_pairwise=False)\n", (6870, 6933), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((7146, 7239), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df.iloc[:, -6:]'], {'target_col': '"""target"""', 'plot_pairwise': '(False)'}), "(df.iloc[:, -6:], target_col='target',\n    plot_pairwise=False)\n", (7176, 7239), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((7479, 7551), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['df'], {'target_col': '"""target"""', 'random_state': '(42)'}), "(df, target_col='target', random_state=42)\n", (7509, 7551), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((8446, 8470), 'sklearn.datasets.make_blobs', 'make_blobs', ([], {'n_samples': '(30)'}), '(n_samples=30)\n', (8456, 8470), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((8482, 8497), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (8494, 8497), True, 'import pandas as pd\n'), ((8506, 8518), 'pandas.Series', 'pd.Series', (['y'], {}), '(y)\n', (8515, 8518), True, 'import pandas as pd\n'), ((8606, 8637), 'dabl.plot.supervised.plot', 'plot', (['data'], {'target_col': '"""target"""'}), "(data, target_col='target')\n", (8610, 8637), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((8694, 8724), 'sklearn.datasets.load_diabetes', 'load_diabetes', ([], {'return_X_y': '(True)'}), '(return_X_y=True)\n', (8707, 8724), False, 'from sklearn.datasets import make_regression, make_blobs, load_digits, fetch_openml, load_diabetes\n'), ((8733, 8748), 'pandas.DataFrame', 'pd.DataFrame', (['X'], {}), '(X)\n', (8745, 8748), True, 'import pandas as pd\n'), ((10239, 10263), 'dabl.plot.supervised.plot', 'plot', (['df'], {'target_col': '"""y"""'}), "(df, target_col='y')\n", (10243, 10263), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((10770, 10814), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df'], {'target_col': 'b'}), '(df, target_col=b)\n', (10796, 10814), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((10941, 10974), 'dabl.set_config', 'set_config', ([], {'truncate_labels': '(False)'}), '(truncate_labels=False)\n', (10951, 10974), False, 'from dabl import set_config\n'), ((10985, 11029), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df'], {'target_col': 'b'}), '(df, target_col=b)\n', (11011, 11029), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((11113, 11145), 'dabl.set_config', 'set_config', ([], {'truncate_labels': '(True)'}), '(truncate_labels=True)\n', (11123, 11145), False, 'from dabl import set_config\n'), ((1859, 1895), 'pandas.concat', 'pd.concat', (['[df_cont, df_cat]'], {'axis': '(1)'}), '([df_cont, df_cat], axis=1)\n', (1868, 1895), True, 'import pandas as pd\n'), ((2096, 2129), 'numpy.random.uniform', 'np.random.uniform', ([], {'size': 'n_samples'}), '(size=n_samples)\n', (2113, 2129), True, 'import numpy as np\n'), ((4334, 4390), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""Less than two classes"""'}), "(ValueError, match='Less than two classes')\n", (4347, 4390), False, 'import pytest\n'), ((4400, 4444), 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', (['X', '"""target"""'], {}), "(X, 'target')\n", (4431, 4444), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4454, 4510), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""Less than two classes"""'}), "(ValueError, match='Less than two classes')\n", (4467, 4510), False, 'import pytest\n'), ((4520, 4563), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['X', '"""target"""'], {}), "(X, 'target')\n", (4550, 4563), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4678, 4728), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need continuous"""'}), "(ValueError, match='need continuous')\n", (4691, 4728), False, 'import pytest\n'), ((4738, 4778), 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', (['X', '"""target"""'], {}), "(X, 'target')\n", (4765, 4778), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4788, 4838), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need continuous"""'}), "(ValueError, match='need continuous')\n", (4801, 4838), False, 'import pytest\n'), ((4848, 4887), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['X', '"""target"""'], {}), "(X, 'target')\n", (4874, 4887), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((4921, 4972), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need categorical"""'}), "(ValueError, match='need categorical')\n", (4934, 4972), False, 'import pytest\n'), ((4982, 5026), 'dabl.plot.supervised.plot_classification_categorical', 'plot_classification_categorical', (['X', '"""target"""'], {}), "(X, 'target')\n", (5013, 5026), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((5036, 5087), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""need categorical"""'}), "(ValueError, match='need categorical')\n", (5049, 5087), False, 'import pytest\n'), ((5097, 5140), 'dabl.plot.supervised.plot_classification_continuous', 'plot_classification_continuous', (['X', '"""target"""'], {}), "(X, 'target')\n", (5127, 5140), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((8803, 8904), 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), "(UserWarning, match=\n    'Missing values in target_col have been removed for regression')\n", (8815, 8904), False, 'import pytest\n'), ((8953, 8974), 'dabl.plot.supervised.plot', 'plot', (['X', '"""target_col"""'], {}), "(X, 'target_col')\n", (8957, 8974), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((8984, 9085), 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), "(UserWarning, match=\n    'Missing values in target_col have been removed for regression')\n", (8996, 9085), False, 'import pytest\n'), ((9134, 9177), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['X', '"""target_col"""'], {}), "(X, 'target_col')\n", (9160, 9177), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((9187, 9288), 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Missing values in target_col have been removed for regression"""'}), "(UserWarning, match=\n    'Missing values in target_col have been removed for regression')\n", (9199, 9288), False, 'import pytest\n'), ((9337, 9381), 'dabl.plot.supervised.plot_regression_categorical', 'plot_regression_categorical', (['X', '"""target_col"""'], {}), "(X, 'target_col')\n", (9364, 9381), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((9829, 9900), 'pytest.warns', 'pytest.warns', (['UserWarning'], {'match': '"""Dropped 1 outliers in column target."""'}), "(UserWarning, match='Dropped 1 outliers in column target.')\n", (9841, 9900), False, 'import pytest\n'), ((9932, 9972), 'dabl.plot.supervised.plot_regression_continuous', 'plot_regression_continuous', (['df', '"""target"""'], {}), "(df, 'target')\n", (9958, 9972), False, 'from dabl.plot.supervised import plot, plot_classification_categorical, plot_classification_continuous, plot_regression_categorical, plot_regression_continuous\n'), ((10728, 10759), 'numpy.random.uniform', 'np.random.uniform', (['(0)', '(0.1)', '(1000)'], {}), '(0, 0.1, 1000)\n', (10745, 10759), True, 'import numpy as np\n'), ((2190, 2223), 'numpy.percentile', 'np.percentile', (['y', '[5, 10, 60, 85]'], {}), '(y, [5, 10, 60, 85])\n', (2203, 2223), True, 'import numpy as np\n'), ((3099, 3129), 'numpy.random.randint', 'np.random.randint', (['(4)'], {'size': '(100)'}), '(4, size=100)\n', (3116, 3129), True, 'import numpy as np\n'), ((6315, 6362), 'pandas.Series', 'pd.Series', (['[6786930208, 2142878625, 9106275431]'], {}), '([6786930208, 2142878625, 9106275431])\n', (6324, 6362), True, 'import pandas as pd\n'), ((10057, 10083), 'numpy.random.normal', 'np.random.normal', ([], {'size': '(300)'}), '(size=300)\n', (10073, 10083), True, 'import numpy as np\n'), ((10676, 10705), 'numpy.random.uniform', 'np.random.uniform', (['(0)', '(1)', '(1000)'], {}), '(0, 1, 1000)\n', (10693, 10705), True, 'import numpy as np\n'), ((1428, 1462), 'sklearn.preprocessing.KBinsDiscretizer', 'KBinsDiscretizer', ([], {'encode': '"""ordinal"""'}), "(encode='ordinal')\n", (1444, 1462), False, 'from sklearn.preprocessing import KBinsDiscretizer\n'), ((1746, 1786), 'pandas.DataFrame', 'pd.DataFrame', (['X_cat'], {'columns': 'cat_columns'}), '(X_cat, columns=cat_columns)\n', (1758, 1786), True, 'import pandas as pd\n'), ((3339, 3348), 'matplotlib.pyplot.gcf', 'plt.gcf', ([], {}), '()\n', (3346, 3348), True, 'import matplotlib.pyplot as plt\n'), ((5888, 5922), 'numpy.random.randint', 'np.random.randint', (['(0)', '(2)'], {'size': '(1000)'}), '(0, 2, size=1000)\n', (5905, 5922), True, 'import numpy as np\n'), ((9505, 9549), 'numpy.random.randint', 'np.random.randint', ([], {'low': '(1)', 'high': '(100)', 'size': '(200)'}), '(low=1, high=100, size=200)\n', (9522, 9549), True, 'import numpy as np\n'), ((9630, 9675), 'numpy.random.randint', 'np.random.randint', ([], {'low': '(50)', 'high': '(100)', 'size': '(200)'}), '(low=50, high=100, size=200)\n', (9647, 9675), True, 'import numpy as np\n'), ((5822, 5857), 'numpy.random.randint', 'np.random.randint', (['(0)', '(10)'], {'size': '(1000)'}), '(0, 10, size=1000)\n', (5839, 5857), True, 'import numpy as np\n'), ((5981, 5999), 'dabl.preprocessing.detect_types', 'detect_types', (['data'], {}), '(data)\n', (5993, 5999), False, 'from dabl.preprocessing import clean, detect_types, guess_ordinal\n')]