The first formula uses (n-1)/(n-k) as the adjustment factor. This does not correctly account for degree of freedom in the denominator, which should be adjusted for both intercept and predictor. The second formular (n-1)/(n-(n+k)) correctly accounts for the degree of freedom, hence gives a more accurate estimate of R-squared.
The second formular aligns with the calculations performed by statsmodels, and other statistical software. This explains why it aligns with your answer.