Skip to content
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

clip() does not work on pint-typed columns #216

Closed
mkaut opened this issue Feb 1, 2024 · 1 comment
Closed

clip() does not work on pint-typed columns #216

mkaut opened this issue Feb 1, 2024 · 1 comment

Comments

@mkaut
Copy link

mkaut commented Feb 1, 2024

Using clip on pint-typed columns issues UnitStrippedWarning with Pint-Pandas 0.5, Pint 0.23 and pandas 2.1.4, on Windows.
For example:

import pandas as pd
import pint_pandas

ureg = pint_pandas.PintType.ureg
lb = ureg.Quantity(2, 'lbf ft')

df = pd.DataFrame({
	"torque": pd.Series([1, 2, 2, 3], dtype="pint[lbf ft]"),
	"angular_velocity": pd.Series([1, 2, 2, 3], dtype="pint[rpm]"),
})
print(df['torque'].clip(lower=lb))

results in

<MY_PATH>\Lib\site-packages\pandas\core\dtypes\missing.py:225: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  return _isna_array(np.asarray(obj), inf_as_na=inf_as_na)
0    2
1    2
2    2
3    3
Name: torque, dtype: pint[foot * force_pound]

It calculates the correct values, but issues a warning.

I have also tested using a non-typed value as the bound and that results in an error (as it should) - except for 0, which for some reason works and does not issue the warning.

@andrewgsavage
Copy link
Collaborator

I don't get that warning using pint master. I thnik hgrecco/pint#1909 removes the warning, so it'll go when the next pint version is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants