Thank you, I see what you mean now.
I guess I expected to get theta of zero for all the terms but the constant, if there was not enough data to get more than a line fit. I have now updated the code to count the number of unique values and never ask for too many terms. Script now runs happily for all my data. The predictions are still a little wild though, I suspect I may be over-fitting. I don't suppose you saw any undocumented features to add a regularisation term in the code :)
Pereant, qui ante nos nostra dixerunt!