Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Aug 4, 2024
1 parent 8ec278e commit 0e3a269
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build/
dist/
MANIFEST
*pytest_cache*
*mypy_cache*
.eggs

# WebDAV file system cache files
Expand Down
1 change: 0 additions & 1 deletion pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def __eq__(self, other):
other = PintType(other)
except (ValueError, errors.UndefinedUnitError):
return False
print(self.units, other.units)
return self.units == other.units

@classmethod
Expand Down
26 changes: 13 additions & 13 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][float]"
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC]"
)
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][float]"
{0: PintArray(q_a_), 1: PintArray(q_b)}, dtype="pint[degC]"
)
tm.assert_equal(result, expected)

Expand Down Expand Up @@ -99,8 +99,8 @@ def _timeit(fun, n_runs=5):
@staticmethod
def _make_df(size, pint_units=True, dtype=float):
if pint_units:
dist_unit = "pint[m][float]"
time_unit = "pint[s][float]"
dist_unit = "pint[m]"
time_unit = "pint[s]"
else:
dist_unit = dtype
time_unit = dtype
Expand Down Expand Up @@ -168,23 +168,23 @@ def test_issue_88():


def test_issue_127():
a = PintType.construct_from_string("pint[dimensionless][float]")
b = PintType.construct_from_string("pint[][float]")
a = PintType.construct_from_string("pint[dimensionless]")
b = PintType.construct_from_string("pint[]")
assert a == b


class TestIssue174(BaseExtensionTests):
def test_sum(self):
if pandas_version_info < (2, 1):
pytest.skip("Pandas reduce functions strip units prior to version 2.1.0")
a = pd.DataFrame([[0, 1, 2], [3, 4, 5]]).astype("pint[m][float]")
a = pd.DataFrame([[0, 1, 2], [3, 4, 5]]).astype("pint[m]")
row_sum = a.sum(axis=0)
expected_1 = pd.Series([3, 5, 7], dtype="pint[m][float]")
expected_1 = pd.Series([3, 5, 7], dtype="pint[m]")

tm.assert_series_equal(row_sum, expected_1)

col_sum = a.sum(axis=1)
expected_2 = pd.Series([3, 12], dtype="pint[m][float]")
expected_2 = pd.Series([3, 12], dtype="pint[m]")

tm.assert_series_equal(col_sum, expected_2)

Expand All @@ -199,7 +199,7 @@ def test_issue_194(dtype):


class TestIssue202(BaseExtensionTests):
def test_dequantify(self):
def test_dequantify_duplicate_col_names(self):
df = pd.DataFrame()
df["test"] = pd.Series([1, 2, 3], dtype="pint[kN]")
df.insert(0, "test", df["test"], allow_duplicates=True)
Expand All @@ -213,7 +213,7 @@ def test_dequantify(self):
"column_names": [None, "unit"],
},
orient="tight",
dtype="Int64",
dtype="float64",
)
result = df.iloc[:, 1:].pint.dequantify()
tm.assert_frame_equal(expected, result)
Expand All @@ -227,7 +227,7 @@ def test_dequantify(self):
"column_names": [None, "unit"],
},
orient="tight",
dtype="Int64",
dtype="float64",
)
result = df.pint.dequantify()
tm.assert_frame_equal(expected, result)
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_issue246(self):

df = df.astype(
{
"a": "pint[m][float]",
"a": "pint[m]",
"b": "pint[m/s]",
"c": "pint[kN]",
}
Expand Down
16 changes: 7 additions & 9 deletions pint_pandas/testsuite/test_pandas_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def test_initialisation(self, data):
# works with PintArray
df = pd.DataFrame(
{
"length": pd.Series([2.0, 3.0], dtype="pint[m][float]"),
"width": PintArray([2.0, 3.0], dtype="pint[m][float]"),
"length": pd.Series([2.0, 3.0], dtype="pint[m]"),
"width": PintArray([2.0, 3.0], dtype="pint[m]"),
"distance": PintArray([2.0, 3.0], dtype="m"),
"height": PintArray([2.0, 3.0], dtype=ureg.m),
"depth": PintArray.from_1darray_quantity(
Expand All @@ -58,10 +58,8 @@ def test_df_operations(self):
# simply a copy of what's in the notebook
df = pd.DataFrame(
{
"torque": pd.Series([1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft][float]"),
"angular_velocity": pd.Series(
[1.0, 2.0, 2.0, 3.0], dtype="pint[rpm][float]"
),
"torque": pd.Series([1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft]"),
"angular_velocity": pd.Series([1.0, 2.0, 2.0, 3.0], dtype="pint[rpm]"),
}
)

Expand Down Expand Up @@ -110,7 +108,7 @@ def test_dequantify(self):
2: 2.0,
3: 3.0,
},
dtype=pd.Float64Dtype(),
dtype="float64",
),
}
)
Expand Down Expand Up @@ -425,7 +423,7 @@ def test_mismatched_dimensions(self):
op(x, y)

def test_numpy_data(self):
foo = PintArray([1, 2, 3], dtype="pint[m][float]")
foo = PintArray([1, 2, 3], dtype="pint[m]")
result = foo.numpy_data
expected = np.array([1, 2, 3], dtype="int64")
expected = np.array([1, 2, 3], dtype="float64")
np.testing.assert_array_equal(result, expected, strict=True)

0 comments on commit 0e3a269

Please sign in to comment.