Skip to content

Commit

Permalink
get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Aug 4, 2024
1 parent 91da320 commit 06f64d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def __init__(self, values, dtype=None, copy=False):
# infer subdtype from values if not given in dtype
if isinstance(dtype, str) and dtype.count("[") <= 1:
_dtype = PintType(dtype)
if isinstance(values, _Quantity):
values = values.m_as(_dtype.units)
values = pd.array(values, copy=copy)
dtype = PintType(units=_dtype.units, subdtype=values.dtype)
# infer units and subdtype from values if no dtype given
Expand Down
12 changes: 6 additions & 6 deletions pint_pandas/testsuite/test_pandas_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def test_df_operations(self):
def test_dequantify(self):
df = pd.DataFrame(
{
"no_unit_column": pd.Series([i for i in range(4)], dtype=float),
"no_unit_column": pd.Series([i for i in range(4)], dtype="Float64"),
"pintarray_column": pd.Series(
[1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft]"
),
}
)
expected = pd.DataFrame(
{
("no_unit_column", "No Unit"): {0: 0.0, 1: 1.0, 2: 2.0, 3: 3.0},
("no_unit_column", "No Unit"): pd.Series({0: 0.0, 1: 1.0, 2: 2.0, 3: 3.0}, dtype="Float64"),
("pintarray_column", "foot * force_pound"): pd.Series(
{
0: 1.0,
Expand All @@ -127,12 +127,12 @@ def test_quantify(self):
2: 2.0,
3: 3.0,
},
}
}, dtype="Float64"
)
df.columns.names = [None, "unit"]
expected = pd.DataFrame(
{
"no_unit_column": pd.Series([i for i in range(4)], dtype=float),
"no_unit_column": pd.Series([i for i in range(4)], dtype="Float64"),
"pintarray_column": pd.Series(
[1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft]"
),
Expand All @@ -145,7 +145,7 @@ def test_quantify(self):
def test_to_base_units(self):
df = pd.DataFrame(
{
"no_unit_column": pd.Series([i for i in range(4)], dtype=float),
"no_unit_column": pd.Series([i for i in range(4)], dtype="Float64"),
"pintarray_column": pd.Series(
[1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft]"
),
Expand All @@ -155,7 +155,7 @@ def test_to_base_units(self):

expected = pd.DataFrame(
{
"no_unit_column": pd.Series([i for i in range(4)], dtype=float),
"no_unit_column": pd.Series([i for i in range(4)], dtype="Float64"),
"pintarray_column": pd.Series(
[
1.3558179483314006,
Expand Down

0 comments on commit 06f64d3

Please sign in to comment.