Purchasing Russian missiles have risks of inviting US sanctions.

Since India is officially a US ally, Why is India purchasing S-400 rather than the US-made missiles (Patriot or David's Sling or THAAD)?