Praise be to Allah, the Lord of the Worlds; and may His blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
The Prophet (Sallallahu Alaihi wa Sallam) said: “A person is upon the religion of his friend, so you have to choose whom you befriend.” [Reported by Ahmad, Abu Dawud and Tirmizi]
Therefore, a Muslim has to keep company, socialize and befriend pious and knowledgeable people.
A person who praises himself due to the abundance of his prayers and good deeds and backbites people is not a good person. Moreover, his actions are considered a curse on him – we seek refuge in Allah from that.
It is not permissible to befriend or keep company with such a person, who should be advised to abandon what he is upon.
It would be more appropriate not to befriend disobedient people or keep company with them so that one would not be cursed while sitting with them. However, it is acceptable to sit and keep company with them in order to advise them and call them to the right path.
Allah knows best.