(self, data)
| 932 | self.fillFormat(data) |
| 933 | |
| 934 | def fillFormat(self, data): |
| 935 | # only the finite values are used to compute the number of digits |
| 936 | finite_vals = data[isfinite(data)] |
| 937 | |
| 938 | # choose exponential mode based on the non-zero finite values: |
| 939 | abs_non_zero = absolute(finite_vals[finite_vals != 0]) |
| 940 | if len(abs_non_zero) != 0: |
| 941 | max_val = np.max(abs_non_zero) |
| 942 | min_val = np.min(abs_non_zero) |
| 943 | with errstate(over='ignore'): # division can overflow |
| 944 | if max_val >= 1.e8 or (not self.suppress_small and |
| 945 | (min_val < 0.0001 or max_val/min_val > 1000.)): |
| 946 | self.exp_format = True |
| 947 | |
| 948 | # do a first pass of printing all the numbers, to determine sizes |
| 949 | if len(finite_vals) == 0: |
| 950 | self.pad_left = 0 |
| 951 | self.pad_right = 0 |
| 952 | self.trim = '.' |
| 953 | self.exp_size = -1 |
| 954 | self.unique = True |
| 955 | self.min_digits = None |
| 956 | elif self.exp_format: |
| 957 | trim, unique = '.', True |
| 958 | if self.floatmode == 'fixed' or self._legacy <= 113: |
| 959 | trim, unique = 'k', False |
| 960 | strs = (dragon4_scientific(x, precision=self.precision, |
| 961 | unique=unique, trim=trim, sign=self.sign == '+') |
| 962 | for x in finite_vals) |
| 963 | frac_strs, _, exp_strs = zip(*(s.partition('e') for s in strs)) |
| 964 | int_part, frac_part = zip(*(s.split('.') for s in frac_strs)) |
| 965 | self.exp_size = max(len(s) for s in exp_strs) - 1 |
| 966 | |
| 967 | self.trim = 'k' |
| 968 | self.precision = max(len(s) for s in frac_part) |
| 969 | self.min_digits = self.precision |
| 970 | self.unique = unique |
| 971 | |
| 972 | # for back-compat with np 1.13, use 2 spaces & sign and full prec |
| 973 | if self._legacy <= 113: |
| 974 | self.pad_left = 3 |
| 975 | else: |
| 976 | # this should be only 1 or 2. Can be calculated from sign. |
| 977 | self.pad_left = max(len(s) for s in int_part) |
| 978 | # pad_right is only needed for nan length calculation |
| 979 | self.pad_right = self.exp_size + 2 + self.precision |
| 980 | else: |
| 981 | trim, unique = '.', True |
| 982 | if self.floatmode == 'fixed': |
| 983 | trim, unique = 'k', False |
| 984 | strs = (dragon4_positional(x, precision=self.precision, |
| 985 | fractional=True, |
| 986 | unique=unique, trim=trim, |
| 987 | sign=self.sign == '+') |
| 988 | for x in finite_vals) |
| 989 | int_part, frac_part = zip(*(s.split('.') for s in strs)) |
| 990 | if self._legacy <= 113: |
| 991 | self.pad_left = 1 + max(len(s.lstrip('-+')) for s in int_part) |
no test coverage detected