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

3 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-07 14:28 +0000

1"""Protocols describing the minimal interfaces required by the _utils subpackage.""" 

2 

3from __future__ import annotations 

4 

5from typing import Protocol, runtime_checkable 

6 

7import polars as pl 

8 

9 

10@runtime_checkable 

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

12 """Structural interface required by :class:`~jquantstats._utils._data.DataUtils`. 

13 

14 Any object satisfying this protocol can be passed as ``data`` without a 

15 concrete dependency on :class:`~jquantstats.data.Data`. 

16 """ 

17 

18 returns: pl.DataFrame 

19 index: pl.DataFrame 

20 

21 @property 

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

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

24 ... 

25 

26 

27@runtime_checkable 

28class PortfolioLike(Protocol): # pragma: no cover 

29 """Structural interface required by :class:`~jquantstats._utils._portfolio.PortfolioUtils`. 

30 

31 Any object satisfying this protocol can be passed as ``portfolio`` without a 

32 concrete dependency on :class:`~jquantstats.portfolio.Portfolio`. 

33 """ 

34 

35 @property 

36 def data(self) -> DataLike: 

37 """Bridge to the Data analytics object for this portfolio.""" 

38 ... 

39 

40 @property 

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

42 """Asset column names.""" 

43 ...