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

fix astype #204

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)
Loading