diff --git a/dev_scripts/test_new_ver.py b/dev_scripts/test_new_ver.py new file mode 100644 index 0000000..2bdf0f3 --- /dev/null +++ b/dev_scripts/test_new_ver.py @@ -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) diff --git a/poetry.lock b/poetry.lock index 082a9ea..a6e264f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -11,6 +11,17 @@ files = [ {file = "alabaster-0.7.16.tar.gz", hash = "sha256:75a8b99c28a5dad50dd7f8ccdd447a121ddb3892da9e53d1ca5cca3106d58d65"}, ] +[[package]] +name = "appdirs" +version = "1.4.4" +description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +optional = false +python-versions = "*" +files = [ + {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, + {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, +] + [[package]] name = "appnope" version = "0.1.4" @@ -730,6 +741,40 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.11.0,<2.12.0" pyflakes = ">=3.1.0,<3.2.0" +[[package]] +name = "flexcache" +version = "0.3" +description = "Saves and loads to the cache a transformed versions of a source object." +optional = false +python-versions = ">=3.9" +files = [ + {file = "flexcache-0.3-py3-none-any.whl", hash = "sha256:d43c9fea82336af6e0115e308d9d33a185390b8346a017564611f1466dcd2e32"}, + {file = "flexcache-0.3.tar.gz", hash = "sha256:18743bd5a0621bfe2cf8d519e4c3bfdf57a269c15d1ced3fb4b64e0ff4600656"}, +] + +[package.dependencies] +typing-extensions = "*" + +[package.extras] +test = ["pytest", "pytest-cov", "pytest-mpl", "pytest-subtests"] + +[[package]] +name = "flexparser" +version = "0.3.1" +description = "Parsing made fun ... using typing." +optional = false +python-versions = ">=3.9" +files = [ + {file = "flexparser-0.3.1-py3-none-any.whl", hash = "sha256:2e3e2936bec1f9277f777ef77297522087d96adb09624d4fe4240fd56885c013"}, + {file = "flexparser-0.3.1.tar.gz", hash = "sha256:36f795d82e50f5c9ae2fde1c33f21f88922fdd67b7629550a3cc4d0b40a66856"}, +] + +[package.dependencies] +typing-extensions = "*" + +[package.extras] +test = ["pytest", "pytest-cov", "pytest-mpl", "pytest-subtests"] + [[package]] name = "fonttools" version = "4.53.1" @@ -1825,22 +1870,30 @@ xmp = ["defusedxml"] [[package]] name = "pint" -version = "0.21.1" +version = "0.24.1" description = "Physical quantities module" optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "Pint-0.21.1-py3-none-any.whl", hash = "sha256:230ebccc312693117ee925c6492b3631c772ae9f7851a4e86080a15e7be692d8"}, - {file = "Pint-0.21.1.tar.gz", hash = "sha256:5d5b6b518d0c5a7ab03a776175db500f1ed1523ee75fb7fafe38af8149431c8d"}, + {file = "Pint-0.24.1-py3-none-any.whl", hash = "sha256:69b05357c4cb2ac8f3346e235aff4477447e2f56805a79a4f59a2b6d5fc32020"}, + {file = "pint-0.24.1.tar.gz", hash = "sha256:8849fe9d7b8532e5a5dc41e719e9e19268e18eac179d9a5645f21929a2a15caf"}, ] +[package.dependencies] +appdirs = ">=1.4.4" +flexcache = ">=0.3" +flexparser = ">=0.3" +typing-extensions = "*" + [package.extras] babel = ["babel (<=2.8)"] +bench = ["pytest", "pytest-codspeed"] dask = ["dask"] mip = ["mip (>=1.13)"] -numpy = ["numpy (>=1.19.5)"] +numpy = ["numpy (>=1.23)"] pandas = ["pint-pandas (>=0.3)"] -test = ["pytest", "pytest-cov", "pytest-mpl", "pytest-subtests"] +test = ["pytest", "pytest-benchmark", "pytest-cov", "pytest-mpl", "pytest-subtests"] +testbase = ["pytest", "pytest-benchmark", "pytest-cov", "pytest-subtests"] uncertainties = ["uncertainties (>=3.1.6)"] xarray = ["xarray"] @@ -2509,13 +2562,13 @@ files = [ [[package]] name = "setuptools" -version = "70.2.0" +version = "70.3.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-70.2.0-py3-none-any.whl", hash = "sha256:b8b8060bb426838fbe942479c90296ce976249451118ef566a5a0b7d8b78fb05"}, - {file = "setuptools-70.2.0.tar.gz", hash = "sha256:bd63e505105011b25c3c11f753f7e3b8465ea739efddaccef8f0efac2137bac1"}, + {file = "setuptools-70.3.0-py3-none-any.whl", hash = "sha256:fe384da74336c398e0d956d1cae0669bc02eed936cdb1d49b57de1990dc11ffc"}, + {file = "setuptools-70.3.0.tar.gz", hash = "sha256:f171bab1dfbc86b132997f26a119f6056a57950d058587841a0082e8830f9dc5"}, ] [package.extras] @@ -2975,4 +3028,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "b1f553938e19efc6a4f7a5ff6bc13cee2f6aa7fd9fb847e890f795e75cbf6f15" +content-hash = "81c3dc0c3378cbd1f104c6b8207f3c9e5fe1566022bb194bfed17a51a0e013f2" diff --git a/portfolyo/core/pfline/interop.py b/portfolyo/core/pfline/interop.py index 22bfd41..128d5cb 100644 --- a/portfolyo/core/pfline/interop.py +++ b/portfolyo/core/pfline/interop.py @@ -8,6 +8,7 @@ import numpy as np import pandas as pd +import pint_pandas from ... import tools from . import classes, create @@ -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_): diff --git a/pyproject.toml b/pyproject.toml index 8c2f794..6d05b6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/core/pfline/test_flat.py b/tests/core/pfline/test_flat.py index a2741a9..5da45e0 100644 --- a/tests/core/pfline/test_flat.py +++ b/tests/core/pfline/test_flat.py @@ -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) diff --git a/tests/tools/visualize/test_plot.py b/tests/tools/visualize/test_plot.py index 16913c7..98b9052 100644 --- a/tests/tools/visualize/test_plot.py +++ b/tests/tools/visualize/test_plot.py @@ -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])