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

"ValueError: fill_value must be a scalar" when concatenating columns requiring fill #165

Closed
burnpanck opened this issue Mar 15, 2023 · 3 comments · Fixed by #187
Closed

Comments

@burnpanck
Copy link
Contributor

The following MWE shows the issue:

import pandas as pd
import pint_pandas

a = pd.Series(index=[1,2],data=pint_pandas.PintArray([0.,1.], u.mm))
b = pd.Series(index=[2,3],data=pint_pandas.PintArray([2.,3.], u.s))

pd.concat([a,b],axis="columns")

With "normal" pint columns, the code works as expected. I partially traced the error down to

fill_value = fill_value.to(self.units).magnitude

which seems to create a 0-d numpy array instead of a numpy scalar.

This may be an impact of a recent change in either pint_pandas or numpy; I already observed that my int(round(some_quantity/other_quantity_of_same_dim)) started to fail and now require a int(round(float(...))) construct.

The relevant versions in my environment are:

numpy: 1.23.5
pandas: 1.5.1
pint: 0.20.1
pint_pandas: 0.3
@burnpanck
Copy link
Contributor Author

Actually, it may depend on the registry... It seems that both are ultimately an effect of ureg.Quantity(float(...)) always returning arrays - there may be a pint registry option that enforces this? I recently started using pint_xarray, and at some point some library (not really sure if it was pint_array) snapped at me about such a setting, but it was in an interactive session with atypical import order, and after a re-load the issue disappeared.

@burnpanck
Copy link
Contributor Author

a.reindex(b.index) also fails with the same error, while a.reindex(b.index, fill_value=np.nan) works.

@burnpanck
Copy link
Contributor Author

Indeed, it is pint-xarray which forces pint.application_registry.force_ndarray_like = True, thus triggering this bug here.

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

Successfully merging a pull request may close this issue.

1 participant