Description
The encoding
property on Variable
has always been an awkward part of Xarray's API, and an example of poor separation of concerns. It add conceptual overhead to all uses of xarray.Variable
, but exists only for the (somewhat niche) benefit of Xarray's backend IO functionality. This is particularly problematic if we consider the possible separation of xarray.Variable
into a separate package to remove the pandas dependency (#3981).
I think a cleaner way to handle encoding
would be to move it from Variable
onto array objects, specifically duck array objects that Xarray creates when loading data from disk. As long as these duck arrays don't "propagate" themselves under array operations but rather turn into raw numpy arrays (or whatever is wrapped), this would automatically resolve all issues around propagating encoding
attributes (e.g., #5065, #1614). And users who don't care about encoding
because they don't use Xarray's IO functionality would never need to think about it.