@@ -101,8 +101,6 @@ def convert_to_string(value):
101
101
class UnitData (object ):
102
102
# debatable makes sense to special code missing values
103
103
spdict = {'nan' : - 1.0 , 'inf' : - 2.0 , '-inf' : - 3.0 }
104
- # used to set out of bounds
105
- LOWER_BOUND = - 4
106
104
107
105
def __init__ (self , data ):
108
106
"""Create mapping between unique categorical values
@@ -113,32 +111,26 @@ def __init__(self, data):
113
111
sequence of values
114
112
"""
115
113
self .seq , self .locs = [], []
116
- self ._set_seq (data )
117
- self ._set_locs (0 )
114
+ self ._set_seq_locs (data , 0 )
118
115
119
116
def update (self , new_data ):
120
- self . _set_seq ( new_data )
121
- value = max (self .locs )
122
- self ._set_locs ( value + 1 )
117
+ # so as not to conflict with spdict
118
+ value = max (max ( self .locs ) + 1 , 0 )
119
+ self ._set_seq_locs ( new_data , value )
123
120
124
- def _set_seq (self , data ):
125
- #magic to make it work under np1.6
121
+ def _set_seq_locs (self , data , value ):
122
+ # magic to make it work under np1.6
126
123
strdata = to_array (data )
127
124
# np.unique makes dateframes work
128
- for d in np .unique (strdata ):
129
- if d not in self .seq :
130
- self .seq .append (convert_to_string (d ))
131
- self .locs .append (UnitData .LOWER_BOUND )
132
-
133
- def _set_locs (self , value ):
134
- for i , s in enumerate (self .seq ):
135
- if s in UnitData .spdict .keys ():
136
- self .locs [i ] = UnitData .spdict [s ]
137
- elif self .locs [i ] == UnitData .LOWER_BOUND :
138
- self .locs [i ] = value
125
+ new_s = [d for d in np .unique (strdata ) if d not in self .seq ]
126
+ for ns in new_s :
127
+ self .seq .append (convert_to_string (ns ))
128
+ if ns in UnitData .spdict .keys ():
129
+ self .locs .append (UnitData .spdict [ns ])
130
+ else :
131
+ self .locs .append (value )
139
132
value += 1
140
133
141
-
142
134
# Connects the convertor to matplotlib
143
135
units .registry [str ] = StrCategoryConverter ()
144
136
units .registry [bytes ] = StrCategoryConverter ()
0 commit comments