Coverage for src / jquantstats / _stats / _protocol.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-26 18:44 +0000

1"""Protocol describing the subset of Data that the _stats mixins require.""" 

2 

3from __future__ import annotations 

4 

5from collections.abc import Iterator 

6from typing import Protocol, runtime_checkable 

7 

8import polars as pl 

9 

10 

11@runtime_checkable 

12class DataLike(Protocol): # pragma: no cover 

13 """Structural interface required by the Stats mixin classes. 

14 

15 Any object satisfying this protocol can be passed as ``data`` to the 

16 mixin methods without a concrete dependency on :class:`~jquantstats._data.Data`. 

17 """ 

18 

19 returns: pl.DataFrame 

20 index: pl.DataFrame 

21 benchmark: pl.DataFrame | None 

22 

23 @property 

24 def date_col(self) -> list[str]: 

25 """Column names used as the date/time index.""" 

26 ... 

27 

28 @property 

29 def assets(self) -> list[str]: 

30 """Names of the asset return columns.""" 

31 ... 

32 

33 @property 

34 def all(self) -> pl.DataFrame: 

35 """Combined DataFrame of returns, index, and benchmark columns.""" 

36 ... 

37 

38 @property 

39 def _periods_per_year(self) -> float: 

40 """Estimated number of return periods per calendar year.""" 

41 ... 

42 

43 def items(self) -> Iterator[tuple[str, pl.Series]]: 

44 """Iterate over (asset_name, returns_series) pairs.""" 

45 ...