Skip to content

Commit

Permalink
Merge #204
Browse files Browse the repository at this point in the history
204: fix astype r=andrewgsavage a=andrewgsavage

- [x] Closes #203 
- [ ] 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


Co-authored-by: Andrew <[email protected]>
  • Loading branch information
bors[bot] and andrewgsavage authored Sep 11, 2023
2 parents ef8a120 + ddbe5b6 commit 2e087e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pint-pandas Changelog
0.6 (unreleased)
----------------

- Nothing changed yet.
- Fix astype issue #196


0.5 (2023-09-07)
Expand Down
4 changes: 3 additions & 1 deletion pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ def astype(self, dtype, copy=True):
return self._to_array_of_quantity(copy=copy)
if is_string_dtype(dtype):
return pd.array([str(x) for x in self.quantity], dtype=dtype)
return pd.array(self.quantity, dtype, copy)
if isinstance(self._data, ExtensionArray):
return self._data.astype(dtype, copy=copy)
return pd.array(self.quantity.m, dtype, copy)

@property
def units(self):
Expand Down
9 changes: 9 additions & 0 deletions pint_pandas/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ def test_sum(self):
expected_2 = pd.Series([3, 12], dtype="pint[m]")

tm.assert_series_equal(col_sum, expected_2)


@pytest.mark.parametrize("dtype", [pd.Float64Dtype(), "float"])
def test_issue_194(dtype):
s0 = pd.Series([1.0, 2.5], dtype=dtype)
s1 = s0.astype("pint[dimensionless]")
s2 = s1.astype(dtype)

tm.assert_series_equal(s0, s2)

0 comments on commit 2e087e6

Please sign in to comment.