Why are you destructively updating the encoding? If we're doing that, we should definitely make a copy first (e.g., `encoding = array.encoding.copy()` above).