Formatter for subtypes of np.complexfloating
| 1243 | |
| 1244 | |
| 1245 | class ComplexFloatingFormat: |
| 1246 | """ Formatter for subtypes of np.complexfloating """ |
| 1247 | def __init__(self, x, precision, floatmode, suppress_small, |
| 1248 | sign=False, *, legacy=None): |
| 1249 | # for backcompatibility, accept bools |
| 1250 | if isinstance(sign, bool): |
| 1251 | sign = '+' if sign else '-' |
| 1252 | |
| 1253 | floatmode_real = floatmode_imag = floatmode |
| 1254 | if legacy <= 113: |
| 1255 | floatmode_real = 'maxprec_equal' |
| 1256 | floatmode_imag = 'maxprec' |
| 1257 | |
| 1258 | self.real_format = FloatingFormat( |
| 1259 | x.real, precision, floatmode_real, suppress_small, |
| 1260 | sign=sign, legacy=legacy |
| 1261 | ) |
| 1262 | self.imag_format = FloatingFormat( |
| 1263 | x.imag, precision, floatmode_imag, suppress_small, |
| 1264 | sign='+', legacy=legacy |
| 1265 | ) |
| 1266 | |
| 1267 | def __call__(self, x): |
| 1268 | r = self.real_format(x.real) |
| 1269 | i = self.imag_format(x.imag) |
| 1270 | |
| 1271 | # add the 'j' before the terminal whitespace in i |
| 1272 | sp = len(i.rstrip()) |
| 1273 | i = i[:sp] + 'j' + i[sp:] |
| 1274 | |
| 1275 | return r + i |
| 1276 | |
| 1277 | |
| 1278 | class _TimelikeFormat: |