Пример #1
0
    def to_string(self):
        series = self.series

        if len(series) == 0:
            return ''

        fmt_index, have_header = self._get_formatted_index()
        fmt_values = self._get_formatted_values()

        maxlen = max(len(x) for x in fmt_index)
        pad_space = min(maxlen, 60)

        result = ['%s   %s'] * len(fmt_values)
        for i, (k, v) in enumerate(izip(fmt_index[1:], fmt_values)):
            try:
                idx = k.ljust(pad_space + _encode_diff(k))
            except UnicodeEncodeError:
                idx = k.ljust(pad_space)
            result[i] = result[i] % (idx, v)

        if self.header and have_header:
            result.insert(0, fmt_index[0])

        footer = self._get_footer()
        if footer:
            result.append(footer)

        if py3compat.PY3:
            return unicode(u'\n'.join(result))
        return com.console_encode(u'\n'.join(result))
Пример #2
0
    def to_string(self):
        series = self.series

        if len(series) == 0:
            return ''

        fmt_index, have_header = self._get_formatted_index()
        fmt_values = self._get_formatted_values()

        maxlen = max(len(x) for x in fmt_index)
        pad_space = min(maxlen, 60)

        result = ['%s   %s'] * len(fmt_values)
        for i, (k, v) in enumerate(izip(fmt_index[1:], fmt_values)):
            try:
                idx = k.ljust(pad_space + _encode_diff(k))
            except UnicodeEncodeError:
                idx = k.ljust(pad_space)
            result[i] = result[i] % (idx, v)

        if self.header and have_header:
            result.insert(0, fmt_index[0])

        footer = self._get_footer()
        if footer:
            result.append(footer)

        if py3compat.PY3:
            return unicode(u'\n'.join(result))
        return com.console_encode(u'\n'.join(result))
Пример #3
0
 def __repr__(self):
     shape = " x ".join([com.pprint_thing(s) for s in self.shape])
     name = type(self).__name__
     result = "%s: %s, %s, dtype %s" % (name, com.pprint_thing(self.items), shape, self.dtype)
     if py3compat.PY3:
         return unicode(result)
     return com.console_encode(result)
Пример #4
0
    def __bytes__(self):
        """
        Return a string representation for a particular Panel

        Invoked by bytes(df) in py3 only.
        Yields a bytestring in both py2/py3.
        """
        return com.console_encode(self.__unicode__())
Пример #5
0
 def __repr__(self):
     shape = ' x '.join([com.pprint_thing(s) for s in self.shape])
     name = type(self).__name__
     result = '%s: %s, %s, dtype %s' % (name, com.pprint_thing(
         self.items), shape, self.dtype)
     if py3compat.PY3:
         return unicode(result)
     return com.console_encode(result)
Пример #6
0
    def __bytes__(self):
        """
        Return a string representation for a particular Panel

        Invoked by bytes(df) in py3 only.
        Yields a bytestring in both py2/py3.
        """
        return com.console_encode(self.__unicode__())
Пример #7
0
    def test_console_encode(self):
        """
        On Python 2, if sys.stdin.encoding is None (IPython with zmq frontend)
        common.console_encode should encode things as utf-8.
        """
        if py3compat.PY3:
            raise nose.SkipTest

        with tm.stdin_encoding(encoding=None):
            result = com.console_encode(u"\u05d0")
            expected = u"\u05d0".encode('utf-8')
            self.assertEqual(result, expected)
Пример #8
0
    def test_console_encode(self):
        """
        On Python 2, if sys.stdin.encoding is None (IPython with zmq frontend)
        common.console_encode should encode things as utf-8.
        """
        if py3compat.PY3:
            raise nose.SkipTest

        with tm.stdin_encoding(encoding=None):
            result = com.console_encode(u"\u05d0")
            expected = u"\u05d0".encode('utf-8')
            self.assertEqual(result, expected)
Пример #9
0
    def test_console_encode(self):
        import sys

        if py3compat.PY3 or sys.stdin.encoding is None:
            raise nose.SkipTest

        # stub test
        # need to mock-out sys.stdin.encoding=None for real test
        result = com.console_encode(u"\u05d0")
        try:
            expected = u"\u05d0".encode(sys.stdin.encoding)

            # lot of console encodings, ISO-8869-1, cp850, etc. won't encode
            # this character
            self.assertEqual(result, expected)
        except UnicodeEncodeError:
            pass
Пример #10
0
    def test_console_encode(self):
        if py3compat.PY3:
            raise nose.SkipTest

        import sys

        # stub test
        # need to mock-out sys.stdin.encoding=None for real test
        result = com.console_encode(u"\u05d0")
        try:
            expected = u"\u05d0".encode(sys.stdin.encoding)

            # lot of console encodings, ISO-8869-1, cp850, etc. won't encode
            # this character
            self.assertEqual(result, expected)
        except UnicodeEncodeError:
            pass
Пример #11
0
def __newrepr__(self):
    """
    Just ads a bit of extra data to the dataframe on printout.  Literally just copied directly from dataframe.__repr__ and
    added print statements.  Dataframe also has a nice ___reprhtml___ method for html accessibility.
    """
    delim = "\t"
    if self.specunit == None:
        specunitout = "None"
    else:
        specunitout = self.full_specunit

    print "**", self.name, "**", delim, "Spectral unit:", specunitout, delim, "Time unit:", "Not Implemented", "\n"

    buf = StringIO()
    if self._need_info_repr_():
        self.info(buf=buf, verbose=self._verbose_info)
    else:
        self.to_string(buf=buf)
    value = buf.getvalue()

    if py3compat.PY3:
        return unicode(value)
    return com.console_encode(value)
Пример #12
0
 def __repr__(self):
     shape = ' x '.join([com.pprint_thing(s) for s in self.shape])
     name = type(self).__name__
     result = '%s: %s, %s, dtype %s' % (name, self.items, shape, self.dtype)
     return com.console_encode(result)  # repr must return byte-string
Пример #13
0
 def __repr__(self):
     shape = ' x '.join([com.pprint_thing(s) for s in self.shape])
     name = type(self).__name__
     result = '%s: %s, %s, dtype %s' % (name, self.items, shape, self.dtype)
     return com.console_encode(result) # repr must return byte-string
Пример #14
0
    def test_console_encode(self):

        # stub test
        # need to mock-out sys.stdin.encoding=None for real test
        result = com.console_encode(u"\u05d0")
        assert not result == '?'