I would change this to:
```
if unit is None:
    unit = x.unit
else:
    unit = u.Unit(unit)
```
The logic is that if no unit is given, the input values have to be quantities. Furthermore, with this change, the next few lines will automatically get all the units on the same scale, and thus you can remove the (slow) `physical_type` check.