New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert all arrays in a dataset into the same unit #45
Comments
when designing this method I considered My only concern when implementing this is that the error reporting could be a pain: there's only a single exception per incompatible dimensionality so we'd have to check the compatibility separately.
yes, please. And don't worry about being slow, we're not in a hurry to release the next version. |
I'm not sure how common this is - single-variable datasets are normally just represented as DataArrays, and multi-variable datasets are (in my personal experience) normally variables with different units, but shared coordinates. There might be another way to do this currently which is possibly slightly nicer too? Something like for var in ds:
var.pint.to('unit') I would be interested to hear how you think the API could be improved though :) |
This is a job for |
thanks for the hint, @dcherian, that does indeed work and would be a bit easier to remember than creating a temporary |
Maybe my use case (one Dataset of DataArrays each describing emissions of one gas) is also special, but I found I need to convert a whole multi-variable Dataset quite often, sometimes just to convert a Dataset into a DataArray, sometimes to normalize to a standard unit before 'dequantify'ing and storing the Dataset as a CSV. |
thanks for sharing your use case, @mikapfl, this makes it so much easier to decide whether or not to include this shortcut. What do you think about the Just for reference, the reason why we have been so reluctant to add this is that if it turns out to be a bad decision later we would have to go through a deprecation cycle to remove it. Then again, the library is intentionally marked with the |
I think Either way you decide, I can prepare a pull request. (-: |
after consideration, I agree that making the API for If you still need this feel free to send in a PR (I'm sorry for taking so long to decide) |
Hi,
If I have a quantified Dataset
ds
, trying to convert all arrays in the Dataset into the same unit yields an error:The workaround is to generate a temporary dictionary like so:
However, I think that is kind of ugly. Given that converting a whole dataset to the same unit is rather intuitive and (I guess) common, I think it would be great if
Dataset.pint.to
supported this directly.I could also have a look at writing a patch, but I'll be at pydata later this week, so I won't be able to look at this until next week.
Cheers,
Mika
The text was updated successfully, but these errors were encountered: