(self)
| 501 | return obj |
| 502 | |
| 503 | def __repr__(self): |
| 504 | |
| 505 | repr_dtype = self.dtype |
| 506 | if ( |
| 507 | self.dtype.type is record or |
| 508 | not issubclass(self.dtype.type, nt.void) |
| 509 | ): |
| 510 | # If this is a full record array (has numpy.record dtype), |
| 511 | # or if it has a scalar (non-void) dtype with no records, |
| 512 | # represent it using the rec.array function. Since rec.array |
| 513 | # converts dtype to a numpy.record for us, convert back |
| 514 | # to non-record before printing |
| 515 | if repr_dtype.type is record: |
| 516 | repr_dtype = sb.dtype((nt.void, repr_dtype)) |
| 517 | prefix = "rec.array(" |
| 518 | fmt = 'rec.array(%s,%sdtype=%s)' |
| 519 | else: |
| 520 | # otherwise represent it using np.array plus a view |
| 521 | # This should only happen if the user is playing |
| 522 | # strange games with dtypes. |
| 523 | prefix = "array(" |
| 524 | fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)' |
| 525 | |
| 526 | # get data/shape string. logic taken from numeric.array_repr |
| 527 | if self.size > 0 or self.shape == (0,): |
| 528 | lst = sb.array2string( |
| 529 | self, separator=', ', prefix=prefix, suffix=',') |
| 530 | else: |
| 531 | # show zero-length shape unless it is (0,) |
| 532 | lst = f"[], shape={repr(self.shape)}" |
| 533 | |
| 534 | lf = '\n' + ' ' * len(prefix) |
| 535 | if _get_legacy_print_mode() <= 113: |
| 536 | lf = ' ' + lf # trailing space |
| 537 | return fmt % (lst, lf, repr_dtype) |
| 538 | |
| 539 | def field(self, attr, val=None): |
| 540 | if isinstance(attr, int): |
nothing calls this directly
no test coverage detected