Closed MichaelTiemannOSC closed 11 months ago
I've come across a similar error message in a different context and I suspect the problem is that the multiplication is prematurely inferring the dtype of the operation from the first multiplication (master scalar?) and wrongly broadcasting that to the rest of the multiplication. But I haven't been inside the code, so cannot say for sure.
I just discovered this workaround for multiplying a DataFrame (of 'pint[dimensionless]' numbers) by a Series (of heterogeneous unts):
df.pint.dequantify().mul(ser, axis=0).droplevel('unit', axis=1)
multiplication is prematurely inferring the dtype of the operation from the first multiplication (master scalar?) and wrongly broadcasting that to the rest of the multiplication.
That's the intention - a PintArray can only hold a single unit, so if it cannot convert to that unit it should error.
I know that PintPandas really only works with PintArrays and not with DataFrames that contain different units on every row. But hear me out. The following shows first the "good" behavior of multiplying DataFrame made from PintArrays by a dimensionless series, followed by things that "work", the last of which throws an error. It is surprising to me that I need to use .pint.m to strip away the dimensionless dimension in order to get Series.mul to work as expected.