Compute arithmetic mode (most common value) of the length of each item in an iterator. Args: x - iterator (list, tuple, etc) Returns: mode - int.
(self, x)
| 947 | return len |
| 948 | |
| 949 | def _mode_len(self, x): |
| 950 | """Compute arithmetic mode (most common value) of the length of each item |
| 951 | in an iterator. |
| 952 | |
| 953 | Args: x - iterator (list, tuple, etc) |
| 954 | Returns: mode - int. |
| 955 | |
| 956 | """ |
| 957 | lens = [self._cell_len(i) for i in x] |
| 958 | m = Counter(lens).most_common() |
| 959 | # If there are a lot of empty columns, use the 2nd most common length |
| 960 | # besides 0 |
| 961 | try: |
| 962 | mode = m[0][0] or m[1][0] |
| 963 | except IndexError: |
| 964 | mode = 0 |
| 965 | max_len = max(lens) or 1 |
| 966 | diff = abs(mode - max_len) |
| 967 | if diff > (self.column_gap * 2) and diff / max_len > 0.1: |
| 968 | return max(max(1, self.column_gap), mode) |
| 969 | else: |
| 970 | return max(max(1, self.column_gap), max_len) |
| 971 | |
| 972 | def _get_column_widths_mode(self, d): |
| 973 | """Given a list of lists, return a list of the variable column width |
no outgoing calls
no test coverage detected