docs: def pformat(arg, width=79, height=24, compact=True):
      """Return pretty formatted representation of object as string.
  
      Whitespace might be altered.
  
      """
      if height is None or height < 1:
          height = 1024
      if width is None or width < 1:
          width = 256
  
      npopt = numpy.get_printoptions()
      numpy.set_printoptions(threshold=100, linewidth=width)
  
      if isinstance(arg, basestring):
          if arg[:5].lower() in ('<?xml', b'<?xml'):
              if isinstance(arg, bytes):
                  arg = bytes2str(arg)
              if height == 1:
                  arg = arg[:4*width]
              else:
                  arg = pformat_xml(arg)
          elif isinstance(arg, bytes):
              if isprintable(arg):
                  arg = bytes2str(arg)
                  arg = clean_whitespace(arg)
              else:
                  numpy.set_printoptions(**npopt)
                  return hexdump(arg, width=width, height=height, modulo=1)
          arg = arg.rstrip()
      elif isinstance(arg, numpy.record):
          arg = arg.pprint()
      else:
          import pprint  # delayed import
          compact = {} if sys.version_info[0] == 2 else dict(compact=compact)
          arg = pprint.pformat(arg, width=width, **compact)
  
      numpy.set_printoptions(**npopt)
  
      if height == 1:
          arg = clean_whitespace(arg, compact=True)
          return arg[:width]
  
      argl = list(arg.splitlines())
      if len(argl) > height:
          arg = '\n'.join(argl[:height//2] + ['...'] + argl[-height//2:])
      return arg