It is narrated from Sayyiduna Anas bin Malik (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "The example of a righteous companion is like that of a perfume seller: even if you do not obtain his perfume, or he (peace and blessings be upon him) said: even if he does not give you any of his perfume, you still get his fragrance. And the example of an evil companion is like that of a blacksmith: even if he does not burn your clothes, his (unpleasant) smell still reaches you."
Related hadith on this topic