#NEWLINE# def test_categories( ) : #NEWLINE# #INDENT# df = pd . DataFrame ( { #NEWLINE# #INDENT# 'x' : [ 1 , 2 , 3 , 4 ] , #NEWLINE# 'y' : pd . Categorical ( [ 'a' , 'b' , 'a' , 'c' ] ) , #NEWLINE# #UNINDENT# } , index = pd . CategoricalIndex ( [ 'x' , 'x' , 'y' , 'y' ] ) ) #NEWLINE# categories = dd . categorical . get_categories ( df ) #NEWLINE# assert ( set ( categories . keys ( ) ) == set ( [ 'y' , '.index' ] ) ) #NEWLINE# assert ( list ( categories [ 'y' ] ) == [ 'a' , 'b' , 'c' ] ) #NEWLINE# assert ( list ( categories [ '.index' ] ) == [ 'x' , 'y' ] ) #NEWLINE# df2 = dd . categorical . strip_categories ( df ) #NEWLINE# assert ( not dd . categorical . get_categories ( df2 ) ) #NEWLINE# df3 = dd . categorical . _categorize ( categories , df2 ) #NEWLINE# tm . assert_frame_equal ( df , df3 )