-
Notifications
You must be signed in to change notification settings - Fork 5
RTFM and could not make pint[Mt CO2] work as a unit #32
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
Comments
Hi, could you post a minimum reproducing example of what you are trying to do? Running the code you posted, I get: NameError Traceback (most recent call last)
<ipython-input-1-c1071259d82c> in <module>
2 one_co2 = unit_registry("CO2")
3
----> 4 x = shell_df[shell_df['Unit']=='Mt CO2']
5 x.astype({'Value': 'pint[Mt CO2]'}).dtypes
NameError: name 'shell_df' is not defined And I'm not completely sure what you are trying to do. Cheers, Mika |
Fixed code so you can run it. Sorry! |
Hi, I haven't worked much with pint-pandas (I did more using pint-xarray because we decided for xarray instead of pandas), but from what I gather the experimental unit support using import pandas as pd
import pint_pandas
from openscm_units import unit_registry
# start using the custom unit registry
pint_pandas.PintType.ureg = unit_registry
x = pd.DataFrame({'value': pd.Series([1.0], dtype='pint[Mt CO2]')})
x["value"].pint.to('CH4 kt', 'SARGWP100') Which will output:
But note that the integration between pandas and pint is experimental, so probably this code will not work next year anymore because something was changed. Also setting the unit registry on the
Cheers, Mika |
Thanks for the responses @mikapfl! @MichaelTiemannOSC, @mikapfl is right that the pint-pandas integration is a little flimsy at times. You can probably tell that by looking at the number of open issues and pull requests in the pint-pandas repository. The current development path is currently stuck by, essentially, this issue pandas-dev/pandas#35131. If you want to dig deeper, see also pandas-dev/pandas#43196 (essentially duplicate of first issue), pandas-dev/pandas#43195 (same as previous but with slightly more info), pandas-dev/pandas#35127 https://github.com/pandas-dev/pandas/pull/39790/files pandas-dev/pandas#39830 (PRs attempting to implement fixes which all stalled as this seems to not be anyone's priority unfortunately). |
Uh oh!
There was an error while loading. Please reload this page.
I've spent a good hour probing docs(and sample notebooks) between openscm-units, openscm, pint, and pint-pandas. What I have not figured out how to do is make this work:
My one_co2 is 1 CO2, but pint complains: UndefinedUnitError: 'CO2' is not defined in the unit registry
What am I missing? What changes could I help put into the docs for others to use openscm-units successfully?
The text was updated successfully, but these errors were encountered: