BUG: fix NameError issue in GH2787