hgrecco / pint-pandas

Pandas support for pint
Other
166 stars 41 forks source link

df.min returning dtype object #155

Closed ricardo-hopker closed 1 year ago

ricardo-hopker commented 1 year ago

Hello! Thank you for the great work.

Today I came across the following problem when doing column-wise min function. The resulting series is object type, and not a pint unit, but each element of the series is a pint class.

import pint import pint_pandas import pandas as pd

test = pd.DataFrame({"torque lb ft": pd.Series([1, 2, 2, 3], dtype="pint[lbf ft]"), "torque Nm": pd.Series([1, 2, 2, 3], dtype="pint[N m]")})

result = test.min(axis=1)

print(result.dtype) 'object

similarly, if the units are the same:

test2 = pd.DataFrame({"torque 1": pd.Series([1, 2, 2, 3], dtype="pint[lbf ft]"), "torque 2": pd.Series([1, 2, 2, 3], dtype="pint[lbf ft]")})

result2 = test2.min(axis=1) print(result2.dtype) ' object