def testBreakingCases(self): """ Testing some cases observed to fail previously """ tab1, tab2, tab3 = None, None, None with self.subTest(msg="charCol with list"): tab1 = TableTools.newTable( TableTools.charCol('tab1', ['A', 'B', 'C', 'D'])) print("tab1 = \n{}".format(TableTools.html(tab1))) with self.subTest(msg="charCol with string"): tab2 = TableTools.newTable(TableTools.charCol('tab2', 'EFGH')) print("tab2 = \n{}".format(TableTools.html(tab2))) with self.subTest(msg="col with single string"): tab3 = TableTools.newTable(TableTools.col('tab3', 'EFGH')) print("tab3 = \n{}".format(TableTools.html(tab3))) del tab1, tab2, tab3
hp = plt.histPlot("S1", t, "X", 5).show() hp = plt.histPlot("S1", t, "X", 0, 10, 5).show() ep = plt.errorBarXY("S1", t, "X", "XLow", "XHigh", "Y", "YLow", "YHigh").show() epBy = plt.errorBarXYBy("S1", t, "X", "XLow", "XHigh", "Y", "YLow", "YHigh", "USym").show() ep2 = plt.errorBarX("S1", t, "X", "XLow", "XHigh", "Y").show() epBy2 = plt.errorBarXBy("S1", t, "X", "XLow", "XHigh", "Y", "USym").show() ep3 = plt.errorBarY("S1", t, "X", "Y", "YLow", "YHigh").show() epBy3 = plt.errorBarYBy("S1", t, "X", "Y", "YLow", "YHigh", "USym").show() doubles = [3, 4, 3, 5, 4, 5] time = 1491946585000000000 t = tt.newTable(tt.col("USym", ["A", "B", "A", "B", "A", "B"]), tt.doubleCol("Open", doubles), tt.doubleCol("High", doubles), tt.doubleCol("Low", doubles), tt.doubleCol("Close", doubles)) t = t.updateView("Time = new DateTime(time + (MINUTE * i))") ohlc = plt.ohlcPlot("Test1", t, "Time", "Open", "High", "Low", "Close") ohlcPlotBy = plt.figure().newChart(0)\ .chartTitle("Chart Title")\ .newAxes()\ .xLabel("X")\ .yLabel("Y")\ .ohlcPlotBy("Test1", t, "Time", "Open", "High", "Low", "Close", "USym") categories = ["Samsung", "Others", "Nokia", "Apple", "MSFT"] valuesD = [27.8, 55.3, 16.8, 17.1, 23.1]
def testColumnSource(self): """ Test cases for colSource(), objColSource() methods & associated newTable() method """ # type inference does not work for list and dicts (i.e. not converted to java collections & maps) colSources = [] names = [] mapSources = {} with self.subTest(msg="colSource with byte"): key, val = "byte", TableTools.colSource(self.nByteArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with short"): key, val = "short", TableTools.colSource(self.nShortArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with int"): key, val = "int", TableTools.colSource(self.nIntArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with long"): key, val = "long", TableTools.colSource(self.nLongArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with float"): key, val = "float", TableTools.colSource(self.nFloatArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with double"): key, val = "double", TableTools.colSource(self.nDoubleArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with char"): key, val = "char", TableTools.colSource(self.nCharArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with string"): key, val = "string", TableTools.colSource(self.nStringArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with boolean"): key, val = "boolean", TableTools.colSource(self.nBooleanArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="colSource with time"): key, val = "time", TableTools.colSource(self.nTimeArray) names.append(key) colSources.append(val) mapSources[key] = val with self.subTest(msg="newTable with name and column source list"): self.assertGreater(len(colSources), 0) # make sure that we even do something useful print("table from [names], [sources] = \n{}".format( TableTools.html(TableTools.newTable(3, names, colSources)))) with self.subTest(msg="newTable with {name: column source} map"): self.assertGreater(len(mapSources), 0) # make sure that we even do something useful print("table from [names : sources] = \n{}".format( TableTools.html(TableTools.newTable(3, mapSources)))) del names, colSources, mapSources names, colSources = [], [] with self.subTest(msg="colSource with int list"): key, val = "intList", TableTools.colSource(self.intList) names.append(key) colSources.append(val) with self.subTest(msg="colSource with float list"): key, val = "floatList", TableTools.colSource(self.floatList) names.append(key) colSources.append(val) with self.subTest(msg="colSource with string list"): key, val = "strList", TableTools.colSource(self.stringList) names.append(key) colSources.append(val) with self.subTest(msg="colSource with char list"): key, val = "charList", TableTools.colSource(self.charList) names.append(key) colSources.append(val) with self.subTest(msg="colSource with boolean list"): key, val = "boolList", TableTools.colSource(self.booleanList) names.append(key) colSources.append(val) with self.subTest(msg="colSource with time list"): key, val = "time", TableTools.colSource(self.timeList) names.append(key) colSources.append(val) print("table from colSource with lists = \n{}".format( TableTools.html(TableTools.newTable(3, names, colSources)))) del names, colSources names, colSources = [], [] with self.subTest(msg="objColSource with string"): key, val = "string", TableTools.objColSource(self.nStringArray) names.append(key) colSources.append(val) with self.subTest(msg="objColSource with boolean"): key, val = "boolean", TableTools.objColSource(self.nBooleanArray) names.append(key) colSources.append(val) with self.subTest(msg="objColSource with time"): key, val = "time", TableTools.objColSource(self.nTimeArray) names.append(key) colSources.append(val) # NOTE: this one is kinda dumb...probably not what anyone wants with self.subTest(msg="objColSource with double primitive"): key, val = "double", TableTools.objColSource(self.nDoubleArray) names.append(key) colSources.append(val) print("table from objColSource = \n{}".format( TableTools.html(TableTools.newTable(3, names, colSources)))) del names, colSources names, colSources = [], [] with self.subTest(msg="objColSource with string list"): key, val = "string", TableTools.objColSource(self.stringList) names.append(key) colSources.append(val) with self.subTest(msg="objColSource with boolean list"): key, val = "boolean", TableTools.objColSource(self.booleanList) names.append(key) colSources.append(val) with self.subTest(msg="objColSource with time list"): key, val = "time", TableTools.objColSource(self.timeList) names.append(key) colSources.append(val) # NOTE: this one is kinda dumb...probably not what anyone wants with self.subTest(msg="objColSource with float list"): key, val = "double", TableTools.objColSource(self.floatList) names.append(key) colSources.append(val) print("table from objColSource with lists = \n{}".format( TableTools.html(TableTools.newTable(3, names, colSources)))) del names, colSources
def testTableBasics(self): """ Test cases for table creation, and a few other basic table methods: diff(), html(), show(), showCommaDelimited(), showWithIndex(), string(), roundDecimalColumns(), roundDecimalColumnsExcept(), merge(), mergeSorted() """ tab, tab2, tab3, tab4, tab5, tab6 = None, None, None, None, None, None with self.subTest(msg="emptyTable(long)"): tab = TableTools.emptyTable(3) # set some cols which aren't dumb tab = tab.update("intCol=(int)i", "fltCol=(float)i*0.5", "dblCol=(double)i*0.3") with self.subTest(msg="newTable(TableDefinition)"): # assuming the first test passed... tab3 = TableTools.newTable(tab.getDefinition()) # Essentially table to string methods with self.subTest(msg="html test"): print("html rendering = \n{}".format(TableTools.html(tab))) with self.subTest(msg="show(Table, *cols)"): print("show =") TableTools.show(tab, "intCol", "dblCol") with self.subTest(msg="show(Table, 2, *cols)"): print("show & row limit =") TableTools.show(tab, 2, "intCol", "dblCol") with self.subTest(msg="showCommaDelimited(Table, *cols)"): print("showCommaDelimited =") TableTools.showCommaDelimited(tab, "intCol", "dblCol") with self.subTest(msg="showCommaDelimited(Table, 2, *cols)"): print("showCommaDelimited & row limit =") TableTools.showCommaDelimited(tab, 2, "intCol", "dblCol") with self.subTest(msg="showWithIndex(Table, *cols)"): print("showWithIndex =") TableTools.showWithIndex(tab, "intCol", "dblCol") with self.subTest(msg="showWithIndex(Table, 2, *cols)"): print("showWithIndex & row limit =") TableTools.showWithIndex(tab, 2, "intCol", "dblCol") with self.subTest(msg="string(Table, *cols)"): print("string =\n {}".format( TableTools.string(tab, "intCol", "dblCol"))) with self.subTest(msg="string(Table, 2, *cols)"): print("string & row limit =\n {}".format( TableTools.string(tab, 2, "intCol", "dblCol"))) with self.subTest(msg="roundDecimalColumns"): tab4 = TableTools.roundDecimalColumns(tab) with self.subTest(msg="roundDecimalColumns(*cols)"): tab5 = TableTools.roundDecimalColumns(tab, "fltCol", "dblCol") with self.subTest(msg="roundDecimalColumnsExcept(*cols)"): tab6 = TableTools.roundDecimalColumns(tab, "fltCol") with self.subTest(msg="diff test of a table with itself"): print("diff output of table with itself = \n{}".format( TableTools.diff(tab, tab, 3))) with self.subTest( msg="diff test of a table with rounded version of itself"): print("diff output of table with rounded version of itself = \n{}". format(TableTools.diff(tab, tab4, 3))) with self.subTest(msg="merge(*tables)"): tab4 = TableTools.merge(tab, tab) with self.subTest(msg="merge([tables])"): tab4 = TableTools.merge([tab, tab]) with self.subTest(msg="mergeSorted(col, [tables])"): tab4 = TableTools.mergeSorted("intCol", [tab, tab]) with self.subTest(msg="merge(col, *tables)"): tab4 = TableTools.mergeSorted("intCol", tab, tab) del tab, tab2, tab3, tab4, tab5, tab6
def testColumnHolder(self): """ Test cases for <primitive>Col() methods & associated newTable() method """ holders = [] junk, tab = None, None with self.subTest(msg="byteCol"): holders.append(TableTools.byteCol("byteCol", self.nByteArray)) with self.subTest(msg="shortCol"): holders.append(TableTools.shortCol("shortCol", self.nShortArray)) with self.subTest(msg="intCol"): holders.append(TableTools.intCol("intCol", self.nIntArray)) with self.subTest(msg="longCol"): holders.append(TableTools.longCol("longCol", self.nLongArray)) with self.subTest(msg="floatCol"): holders.append(TableTools.floatCol("floatCol", self.floatList)) with self.subTest(msg="doubleCol"): holders.append(TableTools.doubleCol("doubleCol", self.nDoubleArray)) with self.subTest(msg="charCol"): holders.append(TableTools.charCol("charCol", self.nCharArray)) with self.subTest(msg="newTable with column holders"): self.assertGreater(len(holders), 0) # make sure that we even do something useful tab = TableTools.newTable(*holders) print("tab =\n{}".format(TableTools.html(tab))) del holders, tab holders = [] with self.subTest(msg="byteCol with list"): holders.append(TableTools.byteCol("byteList", self.intList)) with self.subTest(msg="shortCol with list"): holders.append(TableTools.shortCol("shortList", self.intList)) with self.subTest(msg="intCol with list"): holders.append(TableTools.intCol("intList", self.intList)) with self.subTest(msg="longCol with list"): holders.append(TableTools.longCol("longList", self.intList)) with self.subTest(msg="floatCol with list"): holders.append(TableTools.doubleCol("floatList", self.floatList)) with self.subTest(msg="doubleCol with list"): holders.append(TableTools.doubleCol("doubleList", self.floatList)) with self.subTest(msg="charCol with list"): holders.append(TableTools.charCol("charList", self.charList)) print('prim col from list = \n{}'.format( TableTools.html(TableTools.newTable(*holders)))) del holders holders = [] with self.subTest(msg="col with string array"): holders.append(TableTools.col("stringCol", self.nStringArray)) with self.subTest(msg="col with boolean array"): holders.append(TableTools.col("booleanCol", self.nBooleanArray)) with self.subTest(msg="col with time array"): holders.append(TableTools.col("timeCol", self.nTimeArray)) print('obj col = \n{}'.format( TableTools.html(TableTools.newTable(*holders)))) del holders holders = [] with self.subTest(msg="col with int list"): holders.append(TableTools.col("intList2", self.intList)) with self.subTest(msg="col with double list"): holders.append(TableTools.col("doubleList2", self.floatList)) with self.subTest(msg="col with char list"): holders.append(TableTools.col("stringList", self.stringList)) with self.subTest(msg="col with char list"): holders.append(TableTools.col("charList2", self.charList)) with self.subTest(msg="col with boolean list"): holders.append(TableTools.col("booleanList", self.booleanList)) with self.subTest(msg="col with time list"): holders.append(TableTools.col("timeList", self.timeList)) print('col from list = \n{}'.format( TableTools.html(TableTools.newTable(*holders)))) del holders holders = [] with self.subTest(msg="col with byte"): holders.append(TableTools.col("byteCol", self.nByteArray)) with self.subTest(msg="col with short"): holders.append(TableTools.col("shortCol", self.nShortArray)) with self.subTest(msg="col with int"): holders.append(TableTools.col("intCol", self.nIntArray)) with self.subTest(msg="col with long"): holders.append(TableTools.col("longCol", self.nLongArray)) with self.subTest(msg="col with float"): holders.append(TableTools.col("floatCol", self.nFloatArray)) with self.subTest(msg="col with double"): holders.append(TableTools.col("doubleCol", self.nDoubleArray)) with self.subTest(msg="col with char"): holders.append(TableTools.col("charCol", self.nCharArray)) print("primitive from col =\n{}".format( TableTools.html(TableTools.newTable(*holders)))) del holders