Literal string representation.
(self)
| 3997 | return str(self._insert_masked_print()) |
| 3998 | |
| 3999 | def __repr__(self): |
| 4000 | """ |
| 4001 | Literal string representation. |
| 4002 | |
| 4003 | """ |
| 4004 | if self._baseclass is np.ndarray: |
| 4005 | name = 'array' |
| 4006 | else: |
| 4007 | name = self._baseclass.__name__ |
| 4008 | |
| 4009 | |
| 4010 | # 2016-11-19: Demoted to legacy format |
| 4011 | if np.core.arrayprint._get_legacy_print_mode() <= 113: |
| 4012 | is_long = self.ndim > 1 |
| 4013 | parameters = dict( |
| 4014 | name=name, |
| 4015 | nlen=" " * len(name), |
| 4016 | data=str(self), |
| 4017 | mask=str(self._mask), |
| 4018 | fill=str(self.fill_value), |
| 4019 | dtype=str(self.dtype) |
| 4020 | ) |
| 4021 | is_structured = bool(self.dtype.names) |
| 4022 | key = '{}_{}'.format( |
| 4023 | 'long' if is_long else 'short', |
| 4024 | 'flx' if is_structured else 'std' |
| 4025 | ) |
| 4026 | return _legacy_print_templates[key] % parameters |
| 4027 | |
| 4028 | prefix = f"masked_{name}(" |
| 4029 | |
| 4030 | dtype_needed = ( |
| 4031 | not np.core.arrayprint.dtype_is_implied(self.dtype) or |
| 4032 | np.all(self.mask) or |
| 4033 | self.size == 0 |
| 4034 | ) |
| 4035 | |
| 4036 | # determine which keyword args need to be shown |
| 4037 | keys = ['data', 'mask', 'fill_value'] |
| 4038 | if dtype_needed: |
| 4039 | keys.append('dtype') |
| 4040 | |
| 4041 | # array has only one row (non-column) |
| 4042 | is_one_row = builtins.all(dim == 1 for dim in self.shape[:-1]) |
| 4043 | |
| 4044 | # choose what to indent each keyword with |
| 4045 | min_indent = 2 |
| 4046 | if is_one_row: |
| 4047 | # first key on the same line as the type, remaining keys |
| 4048 | # aligned by equals |
| 4049 | indents = {} |
| 4050 | indents[keys[0]] = prefix |
| 4051 | for k in keys[1:]: |
| 4052 | n = builtins.max(min_indent, len(prefix + keys[0]) - len(k)) |
| 4053 | indents[k] = ' ' * n |
| 4054 | prefix = '' # absorbed into the first indent |
| 4055 | else: |
| 4056 | # each key on its own line, indented by two spaces |
no test coverage detected