Skip to content

Commit

Permalink
unit compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rwijtvliet committed Nov 1, 2024
1 parent ad9b836 commit 97d7dff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion portfolyo/tools/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def assert_series_equal(left: pd.Series, right: pd.Series, *args, **kwargs):
pd.testing.assert_series_equal(leftm, rightm, *args, **kwargs)

# Units must be the same.
assert type(leftu) is type(rightu)
if leftu is None:
assert leftu is rightu
elif isinstance(leftu, pint.Unit): # all values share the same unit, leftu is Unit
assert leftu == rightu
# Use `1*` to turn back into quantity. Ensures 'MWh' and 'MW*h' are the same.
assert 1 * leftu == 1 * rightu
else: # each value has its own unit; leftu is Series
pd.testing.assert_series_equal(leftu, rightu)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/pfline/test_flat_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_makedataframe_freqtz(freq, tz):


@pytest.mark.parametrize("data,expected", TESTCASES_INPUTTYPES)
def test_makedataframe_inputtypes(data: Any, expected: pd.DataFrame):
def test_makedataframe_inputtypes(data: Any, expected: pd.DataFrame | type):
"""Test if dataframe can be created from various input types."""
if type(expected) is type and issubclass(expected, Exception):
with pytest.raises(expected):
Expand Down

0 comments on commit 97d7dff

Please sign in to comment.