Shares in Diamond Foods rose despite the US snack maker posting a second-quarter loss after the company's sales and underlying earnings beat analyst expectations.