Esempio n. 1
0
 def _tabulate(self, tablefmt="simple", rollups=False, rows=10):
     """Pretty tabulated string of all the cached data, and column names"""
     if not self.is_valid(): self.fill(rows=rows)
     # Pretty print cached data
     d = collections.OrderedDict()
     # If also printing the rollup stats, build a full row-header
     if rollups:
         col = next(iter(viewvalues(self._data)))  # Get a sample column
         lrows = len(col['data'])  # Cached rows being displayed
         d[""] = ["type", "mins", "mean", "maxs", "sigma", "zeros", "missing"] + list(map(str, range(lrows)))
     # For all columns...
     for k, v in viewitems(self._data):
         x = v['data']  # Data to display
         t = v["type"]  # Column type
         if t == "enum":
             domain = v['domain']  # Map to cat strings as needed
             x = ["" if math.isnan(idx) else domain[int(idx)] for idx in x]
         elif t == "time":
             x = ["" if math.isnan(z) else time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(z / 1000)) for z in x]
         if rollups:  # Rollups, if requested
             mins = v['mins'][0] if v['mins'] and v["type"] != "enum" else None
             maxs = v['maxs'][0] if v['maxs'] and v["type"] != "enum" else None
             #Cross check type with mean and sigma. Set to None if of type enum.
             if v['type'] == "enum":
                 v['mean'] = v['sigma'] = v['zero_count'] = None
             x = [v['type'], mins, v['mean'], maxs, v['sigma'], v['zero_count'], v['missing_count']] + x
         d[k] = x  # Insert into ordered-dict
     return tabulate.tabulate(d, headers="keys", tablefmt=tablefmt)
Esempio n. 2
0
 def _tabulate(self, tablefmt="simple", rollups=False):
     """Pretty tabulated string of all the cached data, and column names"""
     if not self.is_valid(): self.fill()
     # Pretty print cached data
     d = collections.OrderedDict()
     # If also printing the rollup stats, build a full row-header
     if rollups:
         col = next(iter(viewvalues(self._data)))  # Get a sample column
         lrows = len(col['data'])  # Cached rows being displayed
         d[""] = ["type", "mins", "mean", "maxs", "sigma", "zeros", "missing"] + list(map(str, range(lrows)))
     # For all columns...
     for k, v in viewitems(self._data):
         x = v['data']  # Data to display
         t = v["type"]  # Column type
         if t == "enum":
             domain = v['domain']  # Map to cat strings as needed
             x = ["" if math.isnan(idx) else domain[int(idx)] for idx in x]
         elif t == "time":
             x = ["" if math.isnan(z) else time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(z / 1000)) for z in x]
         if rollups:  # Rollups, if requested
             mins = v['mins'][0] if v['mins'] else None
             maxs = v['maxs'][0] if v['maxs'] else None
             x = [v['type'], mins, v['mean'], maxs, v['sigma'], v['zero_count'], v['missing_count']] + x
         d[k] = x  # Insert into ordered-dict
     return tabulate.tabulate(d, headers="keys", tablefmt=tablefmt)
Esempio n. 3
0
 def assert_coltypes(frame, freal, fenum, fint, fbin, ftime, fstring):
     # The server does not report columns as binary -- instead they are integer.
     fint += fbin
     fbin = 0
     type_counts = defaultdict(int)
     for ft in viewvalues(frame.types):
         type_counts[ft] += 1
     print("Created table with column counts: {%s}" % ", ".join("%s: %d" % t for t in type_counts.items()))
     for ct in ["real", "enum", "int", "time", "string"]:
         assert abs(type_counts[ct] - locals()["f" + ct] * frame.ncol) < 1, \
             "Wrong column count of type %s: %d" % (ct, type_counts[ct])
Esempio n. 4
0
 def assert_coltypes(frame, freal, fenum, fint, fbin, ftime, fstring):
     # The server does not report columns as binary -- instead they are integer.
     fint += fbin
     fbin = 0
     type_counts = defaultdict(int)
     for ft in viewvalues(frame.types):
         type_counts[ft] += 1
     print("Created table with column counts: {%s}" %
           ", ".join("%s: %d" % t for t in type_counts.items()))
     for ct in ["real", "enum", "int", "time", "string"]:
         assert abs(type_counts[ct] - locals()["f" + ct] * frame.ncol) < 1, \
             "Wrong column count of type %s: %d" % (ct, type_counts[ct])