If you move this line below the `is_scalar = jd1.ndim == 0` line, then you can use the `is_scalar` value as an enclosure and not have to  make it an argument.  Then you just have `keepasarray(jd1)`.

It's not a big deal, but I would find the code easier to read if you just make `keepasarray` a local function.