Returns the float values converted into strings using the parameters given at initialisation, as a numpy array
(self)
| 1346 | return formatter |
| 1347 | |
| 1348 | def get_result_as_array(self) -> np.ndarray: |
| 1349 | """ |
| 1350 | Returns the float values converted into strings using |
| 1351 | the parameters given at initialisation, as a numpy array |
| 1352 | """ |
| 1353 | |
| 1354 | def format_with_na_rep( |
| 1355 | values: ArrayLike, formatter: Callable, na_rep: str |
| 1356 | ) -> np.ndarray: |
| 1357 | mask = isna(values) |
| 1358 | formatted = np.array( |
| 1359 | [ |
| 1360 | formatter(val) if not m else na_rep |
| 1361 | for val, m in zip(values.ravel(), mask.ravel(), strict=True) |
| 1362 | ] |
| 1363 | ).reshape(values.shape) |
| 1364 | return formatted |
| 1365 | |
| 1366 | def format_complex_with_na_rep( |
| 1367 | values: ArrayLike, formatter: Callable, na_rep: str |
| 1368 | ) -> np.ndarray: |
| 1369 | real_values = np.real(values).ravel() # type: ignore[arg-type] |
| 1370 | imag_values = np.imag(values).ravel() # type: ignore[arg-type] |
| 1371 | real_mask, imag_mask = isna(real_values), isna(imag_values) |
| 1372 | formatted_lst = [] |
| 1373 | for val, real_val, imag_val, re_isna, im_isna in zip( |
| 1374 | values.ravel(), |
| 1375 | real_values, |
| 1376 | imag_values, |
| 1377 | real_mask, |
| 1378 | imag_mask, |
| 1379 | strict=True, |
| 1380 | ): |
| 1381 | if not re_isna and not im_isna: |
| 1382 | formatted_lst.append(formatter(val)) |
| 1383 | elif not re_isna: # xxx+nanj |
| 1384 | formatted_lst.append(f"{formatter(real_val)}+{na_rep}j") |
| 1385 | elif not im_isna: # nan[+/-]xxxj |
| 1386 | # The imaginary part may either start with a "-" or a space |
| 1387 | imag_formatted = formatter(imag_val).strip() |
| 1388 | if imag_formatted.startswith("-"): |
| 1389 | formatted_lst.append(f"{na_rep}{imag_formatted}j") |
| 1390 | else: |
| 1391 | formatted_lst.append(f"{na_rep}+{imag_formatted}j") |
| 1392 | else: # nan+nanj |
| 1393 | formatted_lst.append(f"{na_rep}+{na_rep}j") |
| 1394 | return np.array(formatted_lst).reshape(values.shape) |
| 1395 | |
| 1396 | if self.formatter is not None: |
| 1397 | return format_with_na_rep(self.values, self.formatter, self.na_rep) |
| 1398 | |
| 1399 | if self.fixed_width: |
| 1400 | threshold = get_option("display.chop_threshold") |
| 1401 | else: |
| 1402 | threshold = None |
| 1403 | |
| 1404 | # if we have a fixed_width, we'll need to try different float_format |
| 1405 | def format_values_with(float_format): |
no test coverage detected