-
Notifications
You must be signed in to change notification settings - Fork 476
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
UnitStrippedWarning with pandas Series #1265
Comments
You aren't telling pandas to store the data using a PintArray so it converts it to a ndarray of objects. You need to use the dtype argument:
|
That makes sense - thanks for the quick response. Some of my confusion comes from the observation that when I do the same thing but with >>> df = pd.DataFrame([[pint.Quantity('8 nm')]], columns=['pint'])
>>> df
pint
0 8 nanometer
>>> df.dtypes
pint object
dtype: object |
I have a similar issue when doing the following:
But the result dataframe looks correct:
How can I force the result to be a Quantity and void the warning? |
it does not look correct; when you can see the unit in the column you can tell it's not read it correct
as opposed to
I suggest reading through the example notebook. https://github.com/hgrecco/pint-pandas/blob/master/notebooks/pint-pandas.ipynb |
@andrewgsavage Thanks for the reply, despite the provided code does work for my previous example, my actual case has multiple units on the same dataframe, imagine something like this:
Ideally I would like to make the column have a type Quantity, instead of actually saying the unit. so each line could have different units. Is this possible? Vitor Henrique |
no, the unit is stored with the column |
TL;DR: I recommend closing this issue (raised by @schlegelp), as it should get resolved by PR #1909. While Let's look at this example
which gives this output
The current release of pint (v0.23.x) throws a
Clearly, this is wrong. The units are not stripped. The code works as expected: it creates a It's not clear whether this bug in the current version of pint is related to the issue brought up by @schlegelp for pint v0.16.1, but at least they are related. However, I can confirm that the code changes in PR #1909 will resolve the problem I'm describing above and silence that warnings. The PR has been merged into the master branch in late Dec '23 and will likely be part of pint v0.24.x when it is published. |
Hi!
First things first: big fan of your library! Second: Apologies if that behaviour is expected and/or there is something about it in the docs that I didn't see.
I ran into some unexpected warning when adding a
pint.Quantity
to apandas.Series
. See this minimal example:I have yet to confirm but I'm 99% certain that this started after I updated
numpy
from1.19.x
to1.20.1
. Otherwise runningpint==0.16.1
andpandas==1.2.3
.I'm happy to just ignore the warning but I was wondering if there is a "correct" way of doing this.
Cheers,
Philipp
The text was updated successfully, but these errors were encountered: