#NEWLINE# def map( self , mapper ) : #NEWLINE# #INDENT# '\n        Apply mapper function to its categories (not codes).\n\n        Parameters\n        ----------\n        mapper : callable\n            Function to be applied. When all categories are mapped\n            to different categories, the result will be Categorical which has\n            the same order property as the original. Otherwise, the result will\n            be np.ndarray.\n\n        Returns\n        -------\n        applied : Categorical or np.ndarray.\n        ' #NEWLINE# new_categories = self . categories . map ( mapper ) #NEWLINE# try : #NEWLINE# #INDENT# return Categorical . from_codes ( self . _codes . copy ( ) , categories = new_categories , ordered = self . ordered ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return np . take ( new_categories , self . _codes )