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

Pr/137 compat check #245

Merged
merged 5 commits into from
Jul 29, 2024
Merged

Pr/137 compat check #245

merged 5 commits into from
Jul 29, 2024

Conversation

MichaelTiemannOSC
Copy link
Collaborator

PR number 137 adds _get_common_dtype to PintType so that PintType operations can be performed on a mix of PintType and numeric values (with the later being promoted to the PintType for the purposes of the operation). However, when there are multiple PintType elements present, it is important that all elements are in fact compatible, lest the operation attempt to combine two PintType elements that are not unit-compatible.

  • Closes # (insert issue number)
  • Executed pre-commit run --all-files with no errors
  • The change is fully covered by automated unit tests
  • Documented in docs/ as appropriate
  • Added an entry to the CHANGES file

PR number 137 adds _get_common_dtype to PintType so that `PintType` operations can be performed on a mix of `PintType` and numeric values (with the later being promoted to the `PintType` for the purposes of the operation).  However, when there are multiple `PintType` elements present, it is important that all elements are in fact compatible, lest the operation attempt to combine two `PintType` elements that are not unit-compatible.
Clean up PR for submission.
@MichaelTiemannOSC
Copy link
Collaborator Author

It appears that the new compatibility check prevents the eval function from operating as expected under Pandas 3.0.0.

@mutricyl

@MichaelTiemannOSC MichaelTiemannOSC mentioned this pull request Jul 19, 2024
11 tasks
Copy link

@ArnaudPel ArnaudPel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to file an issue for this problem, glad to see it is already being addressed 🙇

pint_pandas/pint_array.py Outdated Show resolved Hide resolved
@andrewgsavage andrewgsavage merged commit 1943f2b into master Jul 29, 2024
62 checks passed
@MichaelTiemannOSC
Copy link
Collaborator Author

MichaelTiemannOSC commented Aug 28, 2024

This code used to work, but now fails:

import pandas as pd
import numpy as	np
import pint_pandas

km = pd.Series([1.0, 2.0, np.nan], dtype="pint[km]")
kg = pd.Series([1.0, 2.0, np.nan], dtype="pint[kg]")

xx = pd.DataFrame({"a": km, "b": km})
yy = pd.DataFrame({"a": kg, "b": kg})

zz = pd.concat([xx, yy], axis=0).reset_index()

The [ed2b198](https://github.com/hgrecco/pint-pandas/pull/245/commits/ed2b198a5c0c624d91f971a00f9a49ecc10ea6ba) change is the culprit, I believe.

Note that if we allow PintType to set kind to 'O' (commented out at line 52 of pint_array.py), then PintType behaves well enough for pd.concat to do its job.

@mutricyl
Copy link
Contributor

@MichaelTiemannOSC I do not quite understand how you code used to work since it tries to mix km and kg in the same column which is obviously not possible. Is there an copy/paste issue in your code ?

@MichaelTiemannOSC
Copy link
Collaborator Author

A pandas data frame can collect heterogenous types. They won't be proper PintArrays but they won't fail, either. They are just a series of Quantities with type object.

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 this pull request may close these issues.

4 participants