~ubuntu-branches/ubuntu/wily/spyder/wily

« back to all changes in this revision

Viewing changes to spyderlib/widgets/dicteditorutils.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2015-01-15 12:20:11 UTC
  • mfrom: (18.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150115122011-cc7j5dhy2h9uo13m
Tags: 2.3.2+dfsg-1ubuntu1
Backport patch to support pylint3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import re
14
14
 
15
15
# Local imports
16
 
from spyderlib.py3compat import (NUMERIC_TYPES, TEXT_TYPES,
17
 
                                 to_text_string, is_text_string)
 
16
from spyderlib.py3compat import (NUMERIC_TYPES, TEXT_TYPES, to_text_string,
 
17
                                 is_text_string, is_binary_string)
18
18
from spyderlib.utils import programs
19
19
from spyderlib import dependencies
20
20
from spyderlib.baseconfig import _
137
137
#----Sorting
138
138
def sort_against(lista, listb, reverse=False):
139
139
    """Arrange lista items in the same order as sorted(listb)"""
140
 
    return [item for _, item in sorted(zip(listb, lista), reverse=reverse)]
 
140
    try:
 
141
        return [item for _, item in sorted(zip(listb, lista), reverse=reverse)]
 
142
    except:
 
143
        return lista
141
144
 
142
145
def unsorted_unique(lista):
143
146
    """Removes duplicates from lista neglecting its initial ordering"""
145
148
 
146
149
 
147
150
#----Display <--> Value
148
 
def value_to_display(value, truncate=False,
149
 
                     trunc_len=80, minmax=False, collvalue=True):
 
151
def value_to_display(value, truncate=False, trunc_len=80, minmax=False,
 
152
                     collvalue=True):
150
153
    """Convert value for display purpose"""
151
154
    if minmax and isinstance(value, (ndarray, MaskedArray)):
152
155
        if value.size == 0:
161
164
    if isinstance(value, Image):
162
165
        return '%s  Mode: %s' % (address(value), value.mode)
163
166
    if isinstance(value, DataFrame):
164
 
        return ', '.join(list(value.columns))
 
167
        cols = value.columns
 
168
        cols = [to_text_string(c) for c in cols]
 
169
        return 'Column names: ' + ', '.join(list(cols))
 
170
    if is_binary_string(value):
 
171
        try:
 
172
            value = to_text_string(value, 'utf8')
 
173
        except:
 
174
            pass
165
175
    if not is_text_string(value):
166
176
        if isinstance(value, (list, tuple, dict, set)) and not collvalue:            
167
177
            value = address(value)