def test_look_truncate(): table = (('foo', 'bar'), ('abcd', 1234), ('bcde', 2345)) actual = repr(look(table, truncate=3)) expect = """+-----+-----+ | foo | bar | +=====+=====+ | 'ab | 123 | +-----+-----+ | 'bc | 234 | +-----+-----+ """ eq_(expect, actual) actual = repr(look(table, truncate=3, vrepr=str)) expect = """+-----+-----+ | foo | bar | +=====+=====+ | abc | 123 | +-----+-----+ | bcd | 234 | +-----+-----+ """ eq_(expect, actual)
def _test_create(dbo): expect = (('foo', 'bar'), ('a', 1), ('b', 2)) expect_extended = (('foo', 'bar', 'baz'), ('a', 1, 2.3), ('b', 2, 4.1)) actual = fromdb(dbo, 'SELECT * FROM test_create') debug('verify table does not exist to start with') try: debug(look(actual)) except Exception as e: debug('expected exception: ' + str(e)) else: raise Exception('expected exception not raised') debug('verify cannot write without create') try: todb(expect, dbo, 'test_create') except Exception as e: debug('expected exception: ' + str(e)) else: raise Exception('expected exception not raised') debug('create table and verify') todb(expect, dbo, 'test_create', create=True) ieq(expect, actual) debug(look(actual)) debug('verify cannot overwrite with new cols without recreate') try: todb(expect_extended, dbo, 'test_create') except Exception as e: debug('expected exception: ' + str(e)) else: raise Exception('expected exception not raised') debug('verify recreate') todb(expect_extended, dbo, 'test_create', create=True, drop=True) ieq(expect_extended, actual) debug(look(actual)) debug('horrendous identifiers') table = (('foo foo', 'bar.baz."spong`'), ('a', 1), ('b', 2), ('c', 2)) todb(table, dbo, 'foo " bar`', create=True) actual = fromdb(dbo, 'SELECT * FROM "foo "" bar`"') ieq(table, actual)
def test_look_style_minimal(): table = (('foo', 'bar'), ('a', 1), ('b', 2)) actual = repr(look(table, style='minimal')) expect = """foo bar 'a' 1 'b' 2 """ eq_(expect, actual) etl.config.look_style = 'minimal' actual = repr(look(table)) eq_(expect, actual) etl.config.look_style = 'grid'
def test_look_style_simple(): table = (('foo', 'bar'), ('a', 1), ('b', 2)) actual = repr(look(table, style='simple')) expect = """=== === foo bar === === 'a' 1 'b' 2 === === """ eq_(expect, actual) etl.config.look_style = 'simple' actual = repr(look(table)) eq_(expect, actual) etl.config.look_style = 'grid'
def _print_clusteringMetrics(_kMean, _X): metrics = [['Clustering K-Means', 'Datos obtenidos'], ['Inercia', _kMean.inertia_], ['Entropy', entropy(_kMean.labels_)], ['Silhouette Score', silhouette_score(_X, _kMean.labels_, random_state = 0)], ['Calinski-Harabaz Score', calinski_harabaz_score(_X, _kMean.labels_)], ] print('\nMinería de Datos - Clustering K-Means - <VORT>', '\n') print(_kMean, '\n') print(look(metrics))
def _print_classificationMetrics(_classifier, _predict): metrics = [['Clasificación SVM', 'Datos obtenidos'], ['Interceptación', _classifier.intercept_], ['Accuracy Score', accuracy_score(ones_like(_predict), _predict)], ['F1 Score', f1_score(ones_like(_predict), _predict)], ['Hamming Loss', hamming_loss(ones_like(_predict), _predict)], ] print('\nMinería de Datos - Clasificación SVM - <VORT>', '\n') print(_classifier, '\n') print(look(metrics))
def test_look_width(): table = (('foo', 'bar'), ('a', 1), ('b', 2)) actual = repr(look(table, width=10)) expect = ("+-----+---\n" "| foo | ba\n" "+=====+===\n" "| 'a' | \n" "+-----+---\n" "| 'b' | \n" "+-----+---\n") eq_(expect, actual)
def _print_regressionMetrics(_linear, _X, _y, _predict): metrics = [['Regresión Lineal', 'Datos obtenidos'], ['Coeficiente', _linear.coef_], ['Interceptación', _linear.intercept_], ['Calificación (score)', _linear.score(_X, _y)], ['Variance Score', r2_score(_y, _predict)], ['Explained Variance Score', explained_variance_score(_y, _predict)], ['Mean Squared Error', mean_squared_error(_y, _predict)], ['Mean Absolute Error', mean_absolute_error(_y, _predict)], ] print('\nMinería de Datos - Regresión Lineal - <VORT>', '\n') print(_linear, '\n') print(look(metrics))
def test_look_bool(): table = (('foo', 'bar'), ('a', True), ('b', False)) actual = repr(look(table)) expect = """+-----+-------+ | foo | bar | +=====+=======+ | 'a' | True | +-----+-------+ | 'b' | False | +-----+-------+ """ eq_(expect, actual)
def test_look_index_header(): table = (('foo', 'bar'), ('a', 1), ('b', 2)) actual = repr(look(table, index_header=True)) expect = """+-------+-------+ | 0|foo | 1|bar | +=======+=======+ | 'a' | 1 | +-------+-------+ | 'b' | 2 | +-------+-------+ """ eq_(expect, actual)
def test_look_irregular_rows(): table = (('foo', 'bar'), ('a',), ('b', 2, True)) actual = repr(look(table)) expect = """+-----+-----+------+ | foo | bar | | +=====+=====+======+ | 'a' | | | +-----+-----+------+ | 'b' | 2 | True | +-----+-----+------+ """ eq_(expect, actual)
def test_look(): table = (('foo', 'bar'), ('a', 1), ('b', 2)) actual = repr(look(table)) expect = """+-----+-----+ | foo | bar | +=====+=====+ | 'a' | 1 | +-----+-----+ | 'b' | 2 | +-----+-----+ """ eq_(expect, actual)
def _printAction(): ui.display_plot.figure.clear() ax = ui.display_plot.figure.subplots() ui.display_plot.figure.tight_layout(rect=DISPLAY_LAYOUTS[1]) table(ax, df.last().round(3).head(20), loc='upper center') dflen = len(df.last()) if dflen > 20: ax.set_title( f'Tabla de Datos\n(primeras 20 filas de {dflen} en total)') else: ax.set_title(f'Tabla de Datos\n({dflen} filas en total)') ax.set_axis_off() ui.display_plot.draw() print(f'\n Tabla completa de datos ({len(df.last())} filas). <VORT>') print(look(fromdataframe(df.last().round(3)))) print([dt.name for dt in df.last().dtypes.tolist()]) print('\n\n Descripción de estadística básica de la tabla. <VORT>') print( look(df.last().describe( include='all').round(3).astype(str).to_records())) ui.print('Visualización de la última tabla de datos.')
def _show__rows_from(label, test_rows, limit=0): print(label) print(look(test_rows, limit=limit))