Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_table_with_colalign(self):
"""Table columns can be right justified"""
# First with default alignment
actual_result = Table(['12', '3000', '5'])
expected_strings = ['12',
'3000',
'5']
for s in expected_strings:
message = ('Did not find expected string "%s" in result: %s'
% (s, actual_result))
assert s in str(actual_result).strip(), message
# Then using explicit alignment (all right justified)
# FIXME (Ole): This does not work if e.g. col_align has
# different strings: col_align = ['right', 'left', 'center']
actual_result = Table(['12', '3000', '5'],
col_align=['right', 'right', 'right'])
expected_strings = [
def test_table_caption(self):
"""Test table caption"""
self.html += ' <h2>Caption Top</h2>\n'
expected_result = ('%s%s%s%s' % (self.html_table_start,
self.html_caption,
self.html_body,
self.html_table_end))
actual_result = Table(self.table_data, caption=self.table_caption)
message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
assert expected_result.strip() == str(actual_result).strip(), message
self.html += str(actual_result)
#also test bottom caption
self.html += ' <h2>Caption Bottom</h2>\n'
expected_result = ('%s%s%s%s' % (self.html_table_start,
self.html_bottom_caption,
self.html_body,
self.html_table_end))
actual_result = Table(self.table_data,
caption=self.table_caption,
caption_at_bottom=True)
message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
self.html += str(actual_result)
self.writeHtml('table_caption')
def test_table_cells(self):
"""Test table from individual cells"""
self.html += ' <h2>Using Table Cells</h2>\n'
expected_result = ('%s%s%s' % (self.html_table_start,
self.html_body,
self.html_table_end))
actual_result = Table(self.table_cell_data)
message = 'Expected: %s\n\nGot: %s' % (expected_result, actual_result)
assert expected_result.strip() == str(actual_result).strip(), message
self.html += str(actual_result)
self.writeHtml('table_by_cell_objects')
- pandas_ts: leaf is a regular `tables.Table` instance with a column
named `index`.
- pytables_ts and leaf is a regular `tables.Table` instance. Every column
can contain a time data type so we must inspect every column
- pytables_ts and leaf is a `tables.Array` instance. As it is a homogeneous
data container if a column contains a time data type then every column
contains a time data type. Specific positions are not required.
"""
positions = []
if (ts_kind == 'scikits_ts'):
positions.append(leaf.coldescrs['_dates']._v_pos)
elif (ts_kind == 'pandas_ts'):
positions.append(leaf.coldescrs['index']._v_pos)
elif ts_kind == 'pytables_ts':
if isinstance(leaf, tables.Table):
for name in leaf.colnames:
if leaf.coltypes[name] in ['time32', 'time64']:
positions.append(leaf.coldescrs[name]._v_pos)
else:
positions = [-1]
return positions
The last restriction includes the following cases:
- time fields that are part of a nested field
- time fields in `VLArrays`
- time fields in arrays with more than 2 dimensions
- time fields in arrays with atom shape other than ()
:Parameters:
- `leaf`: the tables.Leaf instance being inspected.
- `node_kind`: a LeafNode attribute that indicates the kind of dataset
:Return ts_kind: a flag indicating the kind of time series found
"""
time_types = ['time32', 'time64']
if isinstance(leaf, tables.Table):
asi = leaf._v_attrs
coltypes = leaf.coltypes
pgroup = leaf._g_getparent()
# Check for Pandas timeseries
pandas_attr = getattr(pgroup._v_attrs, 'pandas_type', None)
if pd and pandas_attr in ['frame', 'frame_table']:
userattrs_names = asi._v_attrnamesuser
dtype_attrs = [n for n in userattrs_names if n.endswith('_dtype')]
dtype_attrs.append('index_kind')
for n in dtype_attrs:
if getattr(asi, n).startswith('datetime'):
return 'pandas_ts'
# Check for scikits.timeseries timeseries
if ts and hasattr(asi, 'CLASS') and (asi.CLASS == 'TimeSeriesTable'):
def printClientTotals(self, doTabs):
table = tables.Table()
table.setDefaultColumnFormats((
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.LEFT_JUSTIFY),
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.LEFT_JUSTIFY),
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
))
table.addHeader(("ID", "Client", "Total", "Unique", "Unique"))
table.addHeader(("", "", "", "Users", "IP addrs"))
for title, clientData in sorted(self.clientTotals.iteritems(), key=lambda x: x[0].lower()):
if title == " TOTAL":
continue
table.addRow((
"%s" % (self.clientIDMap[title],),
def printResponseCounts(self, doTabs):
table = tables.Table()
table.addHeader(("Method", "Av. Response Count",))
table.setDefaultColumnFormats((
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.LEFT_JUSTIFY),
tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
))
for method, value in sorted(self.averageResponseCountByMethod.iteritems(), key=lambda x: x[0]):
if method == " TOTAL":
continue
table.addRow((
method,
value,
))
table.addFooter(("Total:", self.averageResponseCountByMethod[" TOTAL"],))
@dispatch(np.ndarray, tb.Table)
def into(_, t, **kwargs):
res = t[:]
dt_fields = [k for k, v in t.coltypes.items() if v == 'time64']
if not dt_fields:
return res
for f in dt_fields:
# pytables is in seconds since epoch
res[f] *= 1e6
fields = []
for name, dtype in sort_dtype_items(t.coldtypes.items(), t.colnames):
typ = getattr(t.cols, name).type
fields.append((name, {'time64': 'datetime64[us]',
'time32': 'datetime64[D]',
def printUserResponseTimes(self, doTabs):
totalCount = 0
averages = {}
for user in self.userResponseTimes.keys():
count = self.userCounts[user]
total = self.userResponseTimes[user]
averages[user] = total / count
totalCount += total
table = tables.Table()
table.addHeader(("User ID/Client", "Av. Response (ms)", "%% Total",))
table.setDefaultColumnFormats((
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.CENTER_JUSTIFY),
tables.Table.ColumnFormat("%d", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%.1f%%%%", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
))
for key, value in sorted(averages.iteritems(), key=lambda x: x[1], reverse=True):
table.addRow((
key,
value,
safePercent(value, total, 1000.0),
))
table.printTabDelimitedData() if doTabs else table.printTable()
print("")
def printHistogramSummary(stat, index):
print("%s average response histogram" % (index,))
table = tables.Table()
table.addHeader(
("", "<10ms", "10ms<->100ms", "100ms<->1s", "1s<->10s", "10s<->30s", "30s<->60s", ">60s", "Over 1s", "Over 10s"),
)
table.setDefaultColumnFormats(
(
tables.Table.ColumnFormat("%s", tables.Table.ColumnFormat.LEFT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%d (%.1f%%)", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%.1f%%", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
tables.Table.ColumnFormat("%.1f%%", tables.Table.ColumnFormat.RIGHT_JUSTIFY),
)