You should take religion as a standard, and the pleasure of Allah as a scale. The one who benefits you with regard to your religion, hold on to him, unless you cannot endure his companionship. The one who harms you in this regard, cut him off and forsake him, unless you are compelled to keep his company. In this case, such companionship is considered a necessity, and necessities overrule prohibitions (i.e. permit what is normally forbidden), provided that such company does not exceed the scope of necessity.
As for the one who does not harm you with regard to your religion nor benefit you with regard to your worldly life, but he is a pleasant and enjoyable person to be around, you should settle for enjoying his pleasant personality provided that such companionship does not prevent you from carrying out your duties or lead you to futility or sin.
As for the companions who cannot be classified under any of these categories, they are the ones about whom an Arab poet said (translation of meaning):