Skip to content

Commit 5c2ea40

Browse files
committed
merge PR #2086
2 parents 36c4842 + f36591e commit 5c2ea40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1401
-878
lines changed

pandas/core/algorithms.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pandas.lib as lib
1010
import pandas._algos as _algos
1111

12+
1213
def match(to_match, values, na_sentinel=-1):
1314
"""
1415
Compute locations of to_match into values
@@ -36,6 +37,7 @@ def match(to_match, values, na_sentinel=-1):
3637
f = lambda htype, caster: _match_generic(to_match, values, htype, caster)
3738
return _hashtable_algo(f, values.dtype)
3839

40+
3941
def unique(values):
4042
"""
4143
Compute unique values (not necessarily sorted) efficiently from input array
@@ -62,6 +64,7 @@ def count(values, uniques=None):
6264
else:
6365
return _hashtable_algo(f, values.dtype)
6466

67+
6568
def _hashtable_algo(f, dtype):
6669
"""
6770
f(HashTable, type_caster) -> result
@@ -83,13 +86,15 @@ def _count_generic(values, table_type, type_caster):
8386

8487
return Series(counts, index=uniques)
8588

89+
8690
def _match_generic(values, index, table_type, type_caster):
8791
values = type_caster(values)
8892
index = type_caster(index)
8993
table = table_type(min(len(index), 1000000))
9094
table.map_locations(index)
9195
return table.lookup(values)
9296

97+
9398
def _unique_generic(values, table_type, type_caster):
9499
values = type_caster(values)
95100
table = table_type(min(len(values), 1000000))
@@ -138,6 +143,7 @@ def factorize(values, sort=False, order=None, na_sentinel=-1):
138143

139144
return labels, uniques, counts
140145

146+
141147
def value_counts(values, sort=True, ascending=False):
142148
"""
143149
Compute a histogram of the counts of non-null values
@@ -192,6 +198,7 @@ def rank(values, axis=0, method='average', na_option='keep',
192198
ascending=ascending)
193199
return ranks
194200

201+
195202
def quantile(x, q, interpolation_method='fraction'):
196203
"""
197204
Compute sample quantile or quantiles of the input array. For example, q=0.5
@@ -254,8 +261,8 @@ def _get_score(at):
254261
elif interpolation_method == 'higher':
255262
score = values[np.ceil(idx)]
256263
else:
257-
raise ValueError("interpolation_method can only be 'fraction', " \
258-
"'lower' or 'higher'")
264+
raise ValueError("interpolation_method can only be 'fraction' "
265+
", 'lower' or 'higher'")
259266

260267
return score
261268

@@ -265,11 +272,12 @@ def _get_score(at):
265272
q = np.asarray(q, np.float64)
266273
return _algos.arrmap_float64(q, _get_score)
267274

275+
268276
def _interpolate(a, b, fraction):
269277
"""Returns the point at the given fraction between a and b, where
270278
'fraction' must be between 0 and 1.
271279
"""
272-
return a + (b - a)*fraction
280+
return a + (b - a) * fraction
273281

274282

275283
def _get_data_algo(values, func_map):
@@ -287,6 +295,7 @@ def _get_data_algo(values, func_map):
287295
values = com._ensure_object(values)
288296
return f, values
289297

298+
290299
def group_position(*args):
291300
"""
292301
Get group position
@@ -303,19 +312,19 @@ def group_position(*args):
303312

304313

305314
_rank1d_functions = {
306-
'float64' : lib.rank_1d_float64,
307-
'int64' : lib.rank_1d_int64,
308-
'generic' : lib.rank_1d_generic
315+
'float64': lib.rank_1d_float64,
316+
'int64': lib.rank_1d_int64,
317+
'generic': lib.rank_1d_generic
309318
}
310319

311320
_rank2d_functions = {
312-
'float64' : lib.rank_2d_float64,
313-
'int64' : lib.rank_2d_int64,
314-
'generic' : lib.rank_2d_generic
321+
'float64': lib.rank_2d_float64,
322+
'int64': lib.rank_2d_int64,
323+
'generic': lib.rank_2d_generic
315324
}
316325

317326
_hashtables = {
318-
'float64' : lib.Float64HashTable,
319-
'int64' : lib.Int64HashTable,
320-
'generic' : lib.PyObjectHashTable
327+
'float64': lib.Float64HashTable,
328+
'int64': lib.Int64HashTable,
329+
'generic': lib.PyObjectHashTable
321330
}

pandas/core/categorical.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def f(self, other):
2424

2525
return f
2626

27+
2728
class Categorical(object):
2829
"""
2930
Represents a categorical variable in classic R / S-plus fashion
@@ -60,6 +61,7 @@ def from_array(cls, data):
6061
name=getattr(data, 'name', None))
6162

6263
_levels = None
64+
6365
def _set_levels(self, levels):
6466
from pandas.core.index import _ensure_index
6567

@@ -95,7 +97,8 @@ def __repr__(self):
9597

9698
indent = ' ' * (levstring.find('[') + len(levheader) + 1)
9799
lines = levstring.split('\n')
98-
levstring = '\n'.join([lines[0]] + [indent + x.lstrip() for x in lines[1:]])
100+
levstring = '\n'.join([lines[0]] +
101+
[indent + x.lstrip() for x in lines[1:]])
99102

100103
return temp % ('' if self.name is None else self.name,
101104
repr(values), levheader + levstring)

0 commit comments

Comments
 (0)