Distributionally Robust Learning in Heterogeneous Contexts