9
9
from pandas import compat , lib , tslib , _np_version_under1p8
10
10
from pandas .types .cast import _maybe_promote
11
11
from pandas .types .generic import ABCSeries , ABCIndex
12
- from pandas .types .common import (is_integer_dtype ,
12
+ from pandas .types .common import (is_unsigned_integer_dtype ,
13
+ is_signed_integer_dtype ,
14
+ is_integer_dtype ,
13
15
is_int64_dtype ,
14
16
is_categorical_dtype ,
15
17
is_extension_type ,
@@ -363,6 +365,9 @@ def factorize(values, sort=False, order=None, na_sentinel=-1, size_hint=None):
363
365
if isinstance (values , Index ):
364
366
uniques = values ._shallow_copy (uniques , name = None )
365
367
elif isinstance (values , Series ):
368
+ # TODO: This constructor is bugged for uint's, especially
369
+ # np.uint64 due to overflow. Test this for uint behavior
370
+ # once constructor has been fixed.
366
371
uniques = Index (uniques )
367
372
return labels , uniques
368
373
@@ -574,7 +579,27 @@ def mode(values):
574
579
def rank (values , axis = 0 , method = 'average' , na_option = 'keep' ,
575
580
ascending = True , pct = False ):
576
581
"""
582
+ Rank the values along a given axis.
577
583
584
+ Parameters
585
+ ----------
586
+ values : array-like
587
+ Array whose values will be ranked. The number of dimensions in this
588
+ array must not exceed 2.
589
+ axis : int, default 0
590
+ Axis over which to perform rankings.
591
+ method : {'average', 'min', 'max', 'first', 'dense'}, default 'average'
592
+ The method by which tiebreaks are broken during the ranking.
593
+ na_option : {'keep', 'top'}, default 'keep'
594
+ The method by which NaNs are placed in the ranking.
595
+ - ``keep``: rank each NaN value with a NaN ranking
596
+ - ``top``: replace each NaN with either +/- inf so that they
597
+ there are ranked at the top
598
+ ascending : boolean, default True
599
+ Whether or not the elements should be ranked in ascending order.
600
+ pct : boolean, default False
601
+ Whether or not to the display the returned rankings in integer form
602
+ (e.g. 1, 2, 3) or in percentile form (e.g. 0.333..., 0.666..., 1).
578
603
"""
579
604
if values .ndim == 1 :
580
605
f , values = _get_data_algo (values , _rank1d_functions )
@@ -584,6 +609,8 @@ def rank(values, axis=0, method='average', na_option='keep',
584
609
f , values = _get_data_algo (values , _rank2d_functions )
585
610
ranks = f (values , axis = axis , ties_method = method ,
586
611
ascending = ascending , na_option = na_option , pct = pct )
612
+ else :
613
+ raise TypeError ("Array with ndim > 2 are not supported." )
587
614
588
615
return ranks
589
616
@@ -679,12 +706,14 @@ def _broadcast(arr_or_scalar, shape):
679
706
_rank1d_functions = {
680
707
'float64' : algos .rank_1d_float64 ,
681
708
'int64' : algos .rank_1d_int64 ,
709
+ 'uint64' : algos .rank_1d_uint64 ,
682
710
'generic' : algos .rank_1d_generic
683
711
}
684
712
685
713
_rank2d_functions = {
686
714
'float64' : algos .rank_2d_float64 ,
687
715
'int64' : algos .rank_2d_int64 ,
716
+ 'uint64' : algos .rank_2d_uint64 ,
688
717
'generic' : algos .rank_2d_generic
689
718
}
690
719
@@ -911,6 +940,7 @@ def _hashtable_algo(f, values, return_dtype=None):
911
940
912
941
_hashtables = {
913
942
'float64' : (htable .Float64HashTable , htable .Float64Vector ),
943
+ 'uint64' : (htable .UInt64HashTable , htable .UInt64Vector ),
914
944
'int64' : (htable .Int64HashTable , htable .Int64Vector ),
915
945
'string' : (htable .StringHashTable , htable .ObjectVector ),
916
946
'generic' : (htable .PyObjectHashTable , htable .ObjectVector )
@@ -928,11 +958,15 @@ def _get_data_algo(values, func_map):
928
958
f = func_map ['int64' ]
929
959
values = values .view ('i8' )
930
960
931
- elif is_integer_dtype (values ):
961
+ elif is_signed_integer_dtype (values ):
932
962
f = func_map ['int64' ]
933
963
values = _ensure_int64 (values )
934
- else :
935
964
965
+ elif is_unsigned_integer_dtype (values ):
966
+ f = func_map ['uint64' ]
967
+ values = _ensure_uint64 (values )
968
+
969
+ else :
936
970
values = _ensure_object (values )
937
971
938
972
# its cheaper to use a String Hash Table than Object
0 commit comments