Skip to content

Commit

Permalink
subdtype
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Aug 28, 2024
1 parent 99b4c86 commit bc66a5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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":
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

0 comments on commit bc66a5e

Please sign in to comment.