(self)
return '\n'.join(lines)
Returns a pretty string representation of the `FieldIndexer`.
Returns a pretty string representation of the `FieldIndexer`.
Returns a pretty string representation of the FieldIndexer .
def __repr__(self):
    """Returns a pretty string representation of the `FieldIndexer`."""

    def get_name_arr_and_len(dim_idx):
      """Returns a string array of element names and the max name length."""
      axis = self._axes[dim_idx]
      size = self._field.shape[dim_idx]
      try:
        name_len = max(len(name) for name in axis.names)
        name_arr = np.zeros(size, dtype='S{}'.format(name_len))
        for name in axis.names:
          if name:
            # Use the `Axis` object to convert the name into a numpy index, then
            # use this index to write into name_arr.
            name_arr[axis.convert_key_item(name)] = name
      except AttributeError:
        name_arr = np.zeros(size, dtype='S0')  # An array of zero-length strings
        name_len = 0
      return name_arr, name_len

    row_name_arr, row_name_len = get_name_arr_and_len(0)
    if self._field.ndim > 1:
      col_name_arr, col_name_len = get_name_arr_and_len(1)
    else:
      col_name_arr, col_name_len = np.zeros(1, dtype='S0'), 0

    idx_len = int(np.log10(max(self._field.shape[0], 1))) + 1

    cls_template = '{class_name:}({field_name:}):'
    col_template = '{padding:}{col_names:}'
    row_template = '{idx:{idx_len:}} {row_name:>{row_name_len:}} {row_vals:}'

    lines = []

    # Write the class name and field name.
    lines.append(cls_template.format(class_name=self.__class__.__name__,
                                     field_name=self._field_name))

    # Write a header line containing the column names (if there are any).
    if col_name_len:
      col_width = max(col_name_len, 9) + 1
      extra_indent = 4
      padding = ' ' * (idx_len + row_name_len + extra_indent)
      col_names = ''.join(
          '{name:<{width:}}'
          .format(name=util.to_native_string(name), width=col_width)
          for name in col_name_arr)
      lines.append(col_template.format(padding=padding, col_names=col_names))

    # Write the row names (if there are any) and the formatted array values.
    if not self._field.shape[0]:
      lines.append('(empty)')
    else:
      for idx, row in enumerate(self._field):
        row_vals = np.array2string(
            np.atleast_1d(row),
            suppress_small=True,
            formatter={'float_kind': '{: < 9.3g}'.format})
        lines.append(row_template.format(
            idx=idx,
            idx_len=idx_len,
            row_name=util.to_native_string(row_name_arr[idx]),
            row_name_len=row_name_len,
            row_vals=row_vals))
    return '\n'.join(lines)
def __repr__ ( self ) : def get_name_arr_and_len ( dim_idx ) : """Returns a string array of element names and the max name length.""" axis = self . _axes [ dim_idx ] size = self . _field . shape [ dim_idx ] try : name_len = max ( len ( name ) for name in axis . names ) name_arr = np . zeros ( size , dtype = 'S{}' . format ( name_len ) ) for name in axis . names : if name : # Use the `Axis` object to convert the name into a numpy index, then # use this index to write into name_arr. name_arr [ axis . convert_key_item ( name ) ] = name except AttributeError : name_arr = np . zeros ( size , dtype = 'S0' ) # An array of zero-length strings name_len = 0 return name_arr , name_len row_name_arr , row_name_len = get_name_arr_and_len ( 0 ) if self . _field . ndim > 1 : col_name_arr , col_name_len = get_name_arr_and_len ( 1 ) else : col_name_arr , col_name_len = np . zeros ( 1 , dtype = 'S0' ) , 0 idx_len = int ( np . log10 ( max ( self . _field . shape [ 0 ] , 1 ) ) ) + 1 cls_template = '{class_name:}({field_name:}):' col_template = '{padding:}{col_names:}' row_template = '{idx:{idx_len:}} {row_name:>{row_name_len:}} {row_vals:}' lines = [ ] # Write the class name and field name. lines . append ( cls_template . format ( class_name = self . __class__ . __name__ , field_name = self . _field_name ) ) # Write a header line containing the column names (if there are any). if col_name_len : col_width = max ( col_name_len , 9 ) + 1 extra_indent = 4 padding = ' ' * ( idx_len + row_name_len + extra_indent ) col_names = '' . join ( '{name:<{width:}}' . format ( name = util . to_native_string ( name ) , width = col_width ) for name in col_name_arr ) lines . append ( col_template . format ( padding = padding , col_names = col_names ) ) # Write the row names (if there are any) and the formatted array values. if not self . _field . shape [ 0 ] : lines . append ( '(empty)' ) else : for idx , row in enumerate ( self . _field ) : row_vals = np . array2string ( np . atleast_1d ( row ) , suppress_small = True , formatter = { 'float_kind' : '{: < 9.3g}' . format } ) lines . append ( row_template . format ( idx = idx , idx_len = idx_len , row_name = util . to_native_string ( row_name_arr [ idx ] ) , row_name_len = row_name_len , row_vals = row_vals ) ) return '\n' . join ( lines )