Skip to content

Commit

Permalink
fixed interop, still failing on visualise and wavg
Browse files Browse the repository at this point in the history
  • Loading branch information
Alina Voilova committed Jul 10, 2024
1 parent d471cf3 commit 2fe6f0f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 12 deletions.
7 changes: 7 additions & 0 deletions dev_scripts/test_new_ver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pandas as pd
from portfolyo import Kind, dev

i = pd.date_range(
"2020-04-06", "2020-04-16", freq="MS", inclusive="left", tz="Europe/Berlin"
)
pfl = dev.get_flatpfline(i, Kind.COMPLETE)
73 changes: 63 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions portfolyo/core/pfline/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
import pandas as pd
import pint_pandas

from ... import tools
from . import classes, create
Expand Down Expand Up @@ -322,6 +323,10 @@ def _from_data(
elif isinstance(data, pd.Series) and isinstance(data.index, pd.DatetimeIndex):
# timeseries
if hasattr(data, "pint"): # pint timeseries
if not isinstance(data.dtype, pint_pandas.PintType):
data = pd.Series([v.magnitude for v in data.values], data.index).astype(
f"pint[{data.values[0].units}]"
)
return InOp(**{_unit2attr(data.pint.units): data})
elif data.dtype == object: # timeeries of objects -> maybe Quantities?
if len(data) and isinstance(val := data.values[0], tools.unit.Q_):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.rst"
python = "^3.10"
pandas = "^2.0" # pandas 2.1.0 doesn't play nice with pint-pandas. Update when new pint-pandas version is released (>0.5)
matplotlib = "^3.7.2"
pint = "^0.21"
pint = "^0.24"
pint-pandas = "0.6"
colorama = "^0.4.6"
holidays = "^0.32"
Expand Down
2 changes: 1 addition & 1 deletion tests/core/pfline/test_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_flatpfline_asfreqimpossible(freq, newfreq, kind):
"2020-04-06", "2020-04-16", freq=freq, inclusive="left", tz="Europe/Berlin"
)
pfl = dev.get_flatpfline(i, kind)
with pytest.raises(ValueError):
with pytest.raises((ValueError, TypeError)):
_ = pfl.asfreq(newfreq)


Expand Down
1 change: 1 addition & 0 deletions tests/tools/visualize/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_pfline_plot(
index = pd.date_range("2020-01-01", "2021-01-01", freq=freq, tz=None)
pfl = pf.dev.get_pfline(index, nlevels=levels, childcount=childcount, kind=kind)
pfl.plot(children=children)
plt.show()


@pytest.mark.parametrize("childcount", [1, 2, 3])
Expand Down

0 comments on commit 2fe6f0f

Please sign in to comment.