#NEWLINE# def test_rank( self ) : #NEWLINE# #INDENT# tm . _skip_if_no_scipy ( ) #NEWLINE# from scipy.stats import rankdata #NEWLINE# self . ts [ : : 2 ] = np . nan #NEWLINE# self . ts [ : 10 ] [ : : 3 ] = 4.0 #NEWLINE# ranks = self . ts . rank ( ) #NEWLINE# oranks = self . ts . astype ( 'O' ) . rank ( ) #NEWLINE# assert_series_equal ( ranks , oranks ) #NEWLINE# mask = np . isnan ( self . ts ) #NEWLINE# filled = self . ts . fillna ( np . inf ) #NEWLINE# exp = Series ( rankdata ( filled ) , index = filled . index , name = 'ts' ) #NEWLINE# exp [ mask ] = np . nan #NEWLINE# tm . assert_series_equal ( ranks , exp ) #NEWLINE# iseries = Series ( np . arange ( 5 ) . repeat ( 2 ) ) #NEWLINE# iranks = iseries . rank ( ) #NEWLINE# exp = iseries . astype ( float ) . rank ( ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = ( Series ( np . arange ( 5 ) ) + 1.0 ) #NEWLINE# exp = ( iseries / 5.0 ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = Series ( np . repeat ( 1 , 100 ) ) #NEWLINE# exp = Series ( np . repeat ( 0.505 , 100 ) ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries [ 1 ] = np . nan #NEWLINE# exp = Series ( np . repeat ( ( 50.0 / 99.0 ) , 100 ) ) #NEWLINE# exp [ 1 ] = np . nan #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = ( Series ( np . arange ( 5 ) ) + 1.0 ) #NEWLINE# iseries [ 4 ] = np . nan #NEWLINE# exp = ( iseries / 4.0 ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = Series ( np . repeat ( np . nan , 100 ) ) #NEWLINE# exp = iseries . copy ( ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = ( Series ( np . arange ( 5 ) ) + 1 ) #NEWLINE# iseries [ 4 ] = np . nan #NEWLINE# exp = ( iseries / 4.0 ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# rng = date_range ( '1/1/1990' , periods = 5 ) #NEWLINE# iseries = ( Series ( np . arange ( 5 ) , rng ) + 1 ) #NEWLINE# iseries . ix [ 4 ] = np . nan #NEWLINE# exp = ( iseries / 4.0 ) #NEWLINE# iranks = iseries . rank ( pct = True ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = Series ( [ 1e-50 , 1e-100 , 1e-20 , 0.01 , ( 1e-20 + 1e-30 ) , 0.1 ] ) #NEWLINE# exp = Series ( [ 2 , 1 , 3 , 5 , 4 , 6.0 ] ) #NEWLINE# iranks = iseries . rank ( ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# iseries = Series ( [ '3 day' , '1 day 10m' , '-2 day' , pd . NaT ] , dtype = 'm8[ns]' ) #NEWLINE# exp = Series ( [ 3 , 2 , 1 , np . nan ] ) #NEWLINE# iranks = iseries . rank ( ) #NEWLINE# assert_series_equal ( iranks , exp ) #NEWLINE# values = np . array ( [ ( - 50 ) , ( - 1 ) , ( - 1e-20 ) , ( - 1e-25 ) , ( - 1e-50 ) , 0 , 1e-40 , 1e-20 , 1e-10 , 2 , 40 ] , dtype = 'float64' ) #NEWLINE# random_order = np . random . permutation ( len ( values ) ) #NEWLINE# iseries = Series ( values [ random_order ] ) #NEWLINE# exp = Series ( ( random_order + 1.0 ) , dtype = 'float64' ) #NEWLINE# iranks = iseries . rank ( ) #NEWLINE# assert_series_equal ( iranks , exp )