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

subdtype #247

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,15 +864,22 @@ def convert_values(param):
# a TypeError should be raised
res = op(lvalues, rvalues)

subdtype = self.dtype.subdtype
if "truediv" in op.__name__ and subdtype.kind == "i":
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case self can be:

<PintArray>
[1581.2004963851048, 2322.7768972177428, 2065.2759837278822,
 2108.0321074762774,  1922.714515192993]
Length: 5, dtype: pint[USD * percent][float64]

self.dtype is pint[USD * percent][float64] and self.dtype.subdtype is 'float64'. But the string 'float64' does not have a kind attribute.

if isinstance(subdtype, _NumpyEADtype):
subdtype = "float64"
else:
subdtype = "Float64"

if op.__name__ == "divmod":
return (
cls.from_1darray_quantity(res[0], self.dtype.subdtype),
cls.from_1darray_quantity(res[1], self.dtype.subdtype),
cls.from_1darray_quantity(res[0], subdtype),
cls.from_1darray_quantity(res[1], subdtype),
)

if coerce_to_dtype:
try:
res = cls.from_1darray_quantity(res, self.dtype.subdtype)
res = cls.from_1darray_quantity(res, subdtype)
except TypeError:
pass

Expand Down
4 changes: 2 additions & 2 deletions pint_pandas/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_force_ndarray_like(self):

result = pd.concat([a, b], axis=1)
expected = pd.DataFrame(
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC][Int64]"
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC][Int32]"
)
tm.assert_equal(result, expected)

Expand All @@ -64,7 +64,7 @@ def test_offset_concat(self):

result = pd.concat([a, b], axis=1)
expected = pd.DataFrame(
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC][Int64]"
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC][Int32]"
)
tm.assert_equal(result, expected)

Expand Down
Loading