# Path: drain/data.py
# class Column(object):
# class ClassificationData(Step):
# class CreateEngine(Step):
# class CreateDatabase(Step):
# class FromSQL(Step):
# class ToSQL(Step):
# class Merge(Step):
# class ToHDF(Step):
# class Normalize(Step):
# class Revise(Step):
#     def __init__(self, definition, astype=None):
#     def apply(self, df):
#     def __hash__(self):
#     def __eq__(self, other):
#     def run(self):
#     def run(self):
#     def run(self):
#     def __init__(self, query=None, to_str=None, table=None,
#                  tables=None, inputs=None, auto_parse_dates=True,
#                  **read_sql_kwargs):
#     def run(self, engine):
#     def __init__(self, table_name, **kwargs):
#     def run(self, df, db):
#     def run(self, *dfs):
#     def __init__(self, objects_to_ascii=False, **kwargs):
#     def run(self, **kwargs):
#     def dump(self):
#     def load(self):
# def prefix_columns(df, prefix, ignore=[]):
# def expand_dates(df, columns=[]):
# def binarize(df, category_classes, all_classes=True, drop=True,
#              astype=None, inplace=True, min_freq=None):
# def binarize_sets(df, columns, cast=False, drop=True, min_freq=None):
# def counts_to_dicts(df, column):
# def expand_counts(df, column, values=None):
# def binarize_clusters(df, column, n_clusters, train=None):
# def train_test_subset(df, train, test, drop=False):
# def normalize(X, train=None):
#     def run(self, X, train=None):
# def impute(X, value=None, train=None, dropna=True, inplace=True):
# def select_regexes(strings, regexes):
# def exclude_regexes(strings, exclude, include=None):
# def select_features(df, exclude, include=None, inplace=False):
# def null_columns(df, train=None):
# def infinite_columns(df):
# def non_numeric_columns(df):
# def date_censor_sql(date_column, today, column=None):
# def revise_helper(query):
# def revise_sql(query, id_column, output_table, max_date_column,
#                min_date_column, date_column, date, source_id_column=None):
#     def __init__(self, sql, id_column, max_date_column, min_date_column,
#                  date_column, date, from_sql_args=None, source_id_column=None, **kwargs):
#     def run(self, source, revised):
# def date_select(df, date_column, date, delta, max_date_column=None):
# def date_censor(df, date_columns, date):
# def parse_delta(s):
#     X = (X - mu) / sigma
#                 X = X.drop(null_columns, axis=1, inplace=False)
#         X = X.fillna(value.dropna(), inplace=False)
# 
# Path: drain/step.py
# _STEP_CACHE = {}
#     DEFAULT = 1
# def load(steps, reload=False):
#     def __new__(cls, *args, **kwargs):
#     def __init__(self, inputs=None, dependencies=None, **kwargs):
#     def execute(self, inputs=None, output=None, load_targets=False):
#     def _hasher(self):
#     def _digest(self):
#     def get_input(self, value, _search=None):
#     def get_inputs(self, _visited=None):
#     def get_arguments(self, **include):
#     def _output_dirname(self):
#     def _yaml_filename(self):
#     def _dump_dirname(self):
#     def _target_filename(self):
#     def run(self):
#     def load(self):
#     def setup_dump(self):
#     def dump(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, args=None, kwargs=None):
# def _simplify_arguments(arguments):
# def merge_results(inputs, arguments=None):
#     def __init__(self, step, key=None):
#     def run(self, *args, **kwargs):
#     def __init__(self, inputs, mapping):
#     def run(self, *args, **kwargs):
#     def __init__(self, _base, _method_name=None, inputs=None, **kwargs):
#     def run(self, *args, **update_kwargs):
# def _expand_inputs(step, steps=None):
# def _collect_kwargs(step, drop_duplicate_names=True):
# def _output_dirnames(workflow=None, leaf=False):
# class Step(object):
# class Arguments(object):
# class GetItem(Step):
# class MapResults(Step):
# class Call(Step):


from drain import data,step
from datetime import date
import tempfile
import os
import pandas as pd
import numpy as np

def test_to_hdf():
    d = data.ClassificationData()
    h = data.ToHDF(inputs=[d], target=True)

    h.setup_dump()
    h.execute()

    r0, r1 = h.result, d.result

    for key in r1.keys():
       assert r0[key].equals(r1[key])

def test_date_select():
    df = pd.DataFrame({'date':pd.to_datetime(
            [date(2013,m,1) for m in range(1,13)])})
    assert np.array_equal(data.date_select(df, 'date', date(2013,4,1), 'all').values, df.values[0:3])

    # test it on a pandas timestamp column too
    df['date'] = pd.to_datetime(df['date'])
    assert np.array_equal(data.date_select(df, 'date', date(2013,4,1), 'all').values, df.values[0:3])

def test_binarize_inplace():
    df = pd.DataFrame({'a':['b','c']})

# Path: drain/data.py
# class Column(object):
# class ClassificationData(Step):
# class CreateEngine(Step):
# class CreateDatabase(Step):
# class FromSQL(Step):
# class ToSQL(Step):
# class Merge(Step):
# class ToHDF(Step):
# class Normalize(Step):
# class Revise(Step):
#     def __init__(self, definition, astype=None):
#     def apply(self, df):
#     def __hash__(self):
#     def __eq__(self, other):
#     def run(self):
#     def run(self):
#     def run(self):
#     def __init__(self, query=None, to_str=None, table=None,
#                  tables=None, inputs=None, auto_parse_dates=True,
#                  **read_sql_kwargs):
#     def run(self, engine):
#     def __init__(self, table_name, **kwargs):
#     def run(self, df, db):
#     def run(self, *dfs):
#     def __init__(self, objects_to_ascii=False, **kwargs):
#     def run(self, **kwargs):
#     def dump(self):
#     def load(self):
# def prefix_columns(df, prefix, ignore=[]):
# def expand_dates(df, columns=[]):
# def binarize(df, category_classes, all_classes=True, drop=True,
#              astype=None, inplace=True, min_freq=None):
# def binarize_sets(df, columns, cast=False, drop=True, min_freq=None):
# def counts_to_dicts(df, column):
# def expand_counts(df, column, values=None):
# def binarize_clusters(df, column, n_clusters, train=None):
# def train_test_subset(df, train, test, drop=False):
# def normalize(X, train=None):
#     def run(self, X, train=None):
# def impute(X, value=None, train=None, dropna=True, inplace=True):
# def select_regexes(strings, regexes):
# def exclude_regexes(strings, exclude, include=None):
# def select_features(df, exclude, include=None, inplace=False):
# def null_columns(df, train=None):
# def infinite_columns(df):
# def non_numeric_columns(df):
# def date_censor_sql(date_column, today, column=None):
# def revise_helper(query):
# def revise_sql(query, id_column, output_table, max_date_column,
#                min_date_column, date_column, date, source_id_column=None):
#     def __init__(self, sql, id_column, max_date_column, min_date_column,
#                  date_column, date, from_sql_args=None, source_id_column=None, **kwargs):
#     def run(self, source, revised):
# def date_select(df, date_column, date, delta, max_date_column=None):
# def date_censor(df, date_columns, date):
# def parse_delta(s):
#     X = (X - mu) / sigma
#                 X = X.drop(null_columns, axis=1, inplace=False)
#         X = X.fillna(value.dropna(), inplace=False)
# 
# Path: drain/step.py
# _STEP_CACHE = {}
#     DEFAULT = 1
# def load(steps, reload=False):
#     def __new__(cls, *args, **kwargs):
#     def __init__(self, inputs=None, dependencies=None, **kwargs):
#     def execute(self, inputs=None, output=None, load_targets=False):
#     def _hasher(self):
#     def _digest(self):
#     def get_input(self, value, _search=None):
#     def get_inputs(self, _visited=None):
#     def get_arguments(self, **include):
#     def _output_dirname(self):
#     def _yaml_filename(self):
#     def _dump_dirname(self):
#     def _target_filename(self):
#     def run(self):
#     def load(self):
#     def setup_dump(self):
#     def dump(self):
#     def __repr__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, args=None, kwargs=None):
# def _simplify_arguments(arguments):
# def merge_results(inputs, arguments=None):
#     def __init__(self, step, key=None):
#     def run(self, *args, **kwargs):
#     def __init__(self, inputs, mapping):
#     def run(self, *args, **kwargs):
#     def __init__(self, _base, _method_name=None, inputs=None, **kwargs):
#     def run(self, *args, **update_kwargs):
# def _expand_inputs(step, steps=None):
# def _collect_kwargs(step, drop_duplicate_names=True):
# def _output_dirnames(workflow=None, leaf=False):
# class Step(object):
# class Arguments(object):
# class GetItem(Step):
# class MapResults(Step):
# class Call(Step):


# Path: tests/test_data.py
from drain import data,step
from datetime import date
import tempfile
import os
import pandas as pd
import numpy as np


def test_to_hdf():
    d = data.ClassificationData()
    h = data.ToHDF(inputs=[d], target=True)

    h.setup_dump()
    h.execute()

    r0, r1 = h.result, d.result

    for key in r1.keys():
       assert r0[key].equals(r1[key])

def test_date_select():
    df = pd.DataFrame({'date':pd.to_datetime(
            [date(2013,m,1) for m in range(1,13)])})
    assert np.array_equal(data.date_select(df, 'date', date(2013,4,1), 'all').values, df.values[0:3])

    # test it on a pandas timestamp column too
    df['date'] = pd.to_datetime(df['date'])
    assert np.array_equal(data.date_select(df, 'date', date(2013,4,1), 'all').values, df.values[0:3])

def test_binarize_inplace():
    df = pd.DataFrame({'a':['b','c']})

    data.binarize(df, ['a'], inplace=True)