MCPcopy Index your code
hub / github.com/numpy/numpy / __repr__

Method __repr__

numpy/ma/core.py:4081–4177  ·  view source on GitHub ↗

Literal string representation.

(self)

Source from the content-addressed store, hash-verified

4079 return str(self._insert_masked_print())
4080
4081 def __repr__(self):
4082 """
4083 Literal string representation.
4084
4085 """
4086 if self._baseclass is np.ndarray:
4087 name = 'array'
4088 else:
4089 name = self._baseclass.__name__
4090
4091 # 2016-11-19: Demoted to legacy format
4092 if np._core.arrayprint._get_legacy_print_mode() <= 113:
4093 is_long = self.ndim > 1
4094 parameters = {
4095 'name': name,
4096 'nlen': " " * len(name),
4097 'data': str(self),
4098 'mask': str(self._mask),
4099 'fill': str(self.fill_value),
4100 'dtype': str(self.dtype)
4101 }
4102 is_structured = bool(self.dtype.names)
4103 key = '{}_{}'.format(
4104 'long' if is_long else 'short',
4105 'flx' if is_structured else 'std'
4106 )
4107 return _legacy_print_templates[key] % parameters
4108
4109 prefix = f"masked_{name}("
4110
4111 dtype_needed = (
4112 not np._core.arrayprint.dtype_is_implied(self.dtype) or
4113 np.all(self.mask) or
4114 self.size == 0
4115 )
4116
4117 # determine which keyword args need to be shown
4118 keys = ['data', 'mask', 'fill_value']
4119 if dtype_needed:
4120 keys.append('dtype')
4121
4122 # array has only one row (non-column)
4123 is_one_row = builtins.all(dim == 1 for dim in self.shape[:-1])
4124
4125 # choose what to indent each keyword with
4126 min_indent = 2
4127 if is_one_row:
4128 # first key on the same line as the type, remaining keys
4129 # aligned by equals
4130 indents = {}
4131 indents[keys[0]] = prefix
4132 for k in keys[1:]:
4133 n = builtins.max(min_indent, len(prefix + keys[0]) - len(k))
4134 indents[k] = ' ' * n
4135 prefix = '' # absorbed into the first indent
4136 else:
4137 # each key on its own line, indented by two spaces
4138 indents = dict.fromkeys(keys, ' ' * min_indent)

Callers 1

__repr__Method · 0.45

Calls 5

_insert_masked_printMethod · 0.95
itemMethod · 0.80
joinMethod · 0.80
allMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected