Formatter for subtypes of np.complexfloating
| 1339 | |
| 1340 | |
| 1341 | class ComplexFloatingFormat: |
| 1342 | """ Formatter for subtypes of np.complexfloating """ |
| 1343 | def __init__(self, x, precision, floatmode, suppress_small, |
| 1344 | sign=False, *, legacy=None): |
| 1345 | # for backcompatibility, accept bools |
| 1346 | if isinstance(sign, bool): |
| 1347 | sign = '+' if sign else '-' |
| 1348 | |
| 1349 | floatmode_real = floatmode_imag = floatmode |
| 1350 | if legacy <= 113: |
| 1351 | floatmode_real = 'maxprec_equal' |
| 1352 | floatmode_imag = 'maxprec' |
| 1353 | |
| 1354 | self.real_format = FloatingFormat( |
| 1355 | x.real, precision, floatmode_real, suppress_small, |
| 1356 | sign=sign, legacy=legacy |
| 1357 | ) |
| 1358 | self.imag_format = FloatingFormat( |
| 1359 | x.imag, precision, floatmode_imag, suppress_small, |
| 1360 | sign='+', legacy=legacy |
| 1361 | ) |
| 1362 | |
| 1363 | def __call__(self, x): |
| 1364 | r = self.real_format(x.real) |
| 1365 | i = self.imag_format(x.imag) |
| 1366 | |
| 1367 | # add the 'j' before the terminal whitespace in i |
| 1368 | sp = len(i.rstrip()) |
| 1369 | i = i[:sp] + 'j' + i[sp:] |
| 1370 | |
| 1371 | return r + i |
| 1372 | |
| 1373 | |
| 1374 | class _TimelikeFormat: |
no outgoing calls
no test coverage detected
searching dependent graphs…