diff --git a/portfolyo/tools/intersect.py b/portfolyo/tools/intersect.py index 2ccf9b3..c953d38 100644 --- a/portfolyo/tools/intersect.py +++ b/portfolyo/tools/intersect.py @@ -214,8 +214,7 @@ def frames( Returns ------- - list of series and/or dataframes - As input, but trimmed to their intersection. + As input, but trimmed to their intersection. Notes ----- @@ -228,4 +227,4 @@ def frames( ignore_tz=ignore_tz, ignore_start_of_day=ignore_start_of_day, ) - return [fr.loc[idx] for idx, fr in zip(new_idxs, frames)] + return [fr.loc[i] for i, fr in zip(new_idxs, frames)] diff --git a/portfolyo/tools/product.py b/portfolyo/tools/product.py index 152fc54..c9fbb0e 100644 --- a/portfolyo/tools/product.py +++ b/portfolyo/tools/product.py @@ -1,7 +1,6 @@ """Utilities for calculating / manipulating price data.""" import datetime as dt -import warnings from typing import Tuple import pandas as pd @@ -14,31 +13,11 @@ def is_peak_hour(i: pd.DatetimeIndex) -> pd.Series: - """ - Calculate if a timestamp is in a peak period or not. - - Parameters - ---------- - i : pd.DatetimeIndex - Timestamps for which to calculate if it falls in a peak period. - - More precisely: if timestamp lies in one of the (left-closed) time intervals that - define the peak hour periods. - - Returns - ------- - Series - with boolean values and same index. - """ - if isinstance(i, pd.Timestamp): - raise TypeError("no longer supported") - warnings.warn( - "Calling this function with a single timestamp is deprecated and will be removed in a future version", - FutureWarning, - ) - return is_peak_hour(pd.DatetimeIndex([i], freq="15T"))[0] - - return germanpower_peakfn(i) + raise DeprecationWarning( + "``pf.is_peak_hour`` has been deprecated and will be removed in a future version." + " Use ``pf.germanpower_peakfn`` instead, or create your own peak function with" + " ``pf.create_peakfn()``." + ) def delivery_period( @@ -59,7 +38,7 @@ def delivery_period( front_count : int, optional (default: 1) 1 = next/coming (full) period, 2 = period after that, etc. start_of_day : dt.time, optional (default: midnight) - Start of day for delivery periods with a longer-than-daily frequency. + Start of day for delivery periods with a daily-or-longer frequency. Returns ------- diff --git a/portfolyo/tools2/intersect.py b/portfolyo/tools2/intersect.py index 0fc6017..41d2278 100644 --- a/portfolyo/tools2/intersect.py +++ b/portfolyo/tools2/intersect.py @@ -1,21 +1,21 @@ from typing import List -from ..tools.intersect import indices_flex -from .types import NDFrameLike +from ..tools import intersect as tools_intersect +from .types import Indexable def indexable( - *frames: NDFrameLike, + *objs: Indexable, ignore_freq: bool = False, ignore_tz: bool = False, ignore_start_of_day: bool = False, -) -> List[NDFrameLike]: +) -> List[Indexable]: """Intersect several dataframes and/or series. Parameters ---------- - *frames : pd.Series and/or pd.DataFrame and/or PfLines and/or PfStates - The frames to intersect. + *objs : pd.Series and/or pd.DataFrame and/or PfLines and/or PfStates + The indexable objects to intersect. ignore_freq: bool, optional (default: False) If True, do the intersection even if the frequencies do not match; drop the time periods that do not (fully) exist in either of the frames. @@ -28,18 +28,17 @@ def indexable( Returns ------- - list of series and/or dataframes - As input, but trimmed to their intersection. + As input, but trimmed to their intersection. Notes ----- The indices must have equal frequency, timezone, start-of-day. Otherwise, an error is raised. If there is no overlap, empty frames are returned. """ - new_idxs = indices_flex( - *[fr.index for fr in frames], + new_idxs = tools_intersect.indices_flex( + *[o.index for o in objs], ignore_freq=ignore_freq, ignore_tz=ignore_tz, ignore_start_of_day=ignore_start_of_day, ) - return [fr.loc[idx] for idx, fr in zip(new_idxs, frames)] + return [o.loc[i] for i, o in zip(new_idxs, objs)] diff --git a/portfolyo/tools2/types.py b/portfolyo/tools2/types.py index 79f3264..8805c4d 100644 --- a/portfolyo/tools2/types.py +++ b/portfolyo/tools2/types.py @@ -7,4 +7,6 @@ from ..core.pfline import PfLine from ..core.pfstate import PfState -NDFrameLike = TypeVar("NDFrameLike", pd.Series, pd.DataFrame, PfLine, PfState) +Indexable = TypeVar( + "Series_DataFrame_PfLine_PfState", pd.Series, pd.DataFrame, PfLine, PfState +)