Skip to content
This repository was archived by the owner on Apr 26, 2025. It is now read-only.

Commit e320f87

Browse files
committed
Move caching decorator from types to utils module.
1 parent 27da135 commit e320f87

5 files changed

Lines changed: 32 additions & 27 deletions

File tree

sec_cik_mapper/BaseMapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import requests
1111

1212
from .retrievers import MutualFundRetriever, StockRetriever
13-
from .types import CompanyData, FieldIndices, Fields, KeyToValueSet, cache
13+
from .types import CompanyData, FieldIndices, Fields, KeyToValueSet
14+
from .utils import with_cache
1415

1516

1617
class BaseMapper:
@@ -87,7 +88,7 @@ def _form_kv_mapping(self, keys: pd.Series, values: pd.Series) -> Dict[str, str]
8788
return {k: v for k, v in zip(keys, values) if k and v}
8889

8990
@property # type: ignore
90-
@cache
91+
@with_cache
9192
def cik_to_tickers(self) -> KeyToValueSet:
9293
"""Get CIK to tickers mapping.
9394
@@ -106,7 +107,7 @@ def cik_to_tickers(self) -> KeyToValueSet:
106107
return self._form_kv_set_mapping(cik_col, ticker_col)
107108

108109
@property # type: ignore
109-
@cache
110+
@with_cache
110111
def ticker_to_cik(self) -> Dict[str, str]:
111112
"""Get ticker to CIK mapping.
112113
@@ -125,7 +126,6 @@ def ticker_to_cik(self) -> Dict[str, str]:
125126
return self._form_kv_mapping(ticker_col, cik_col)
126127

127128
@property # type: ignore
128-
@cache
129129
def raw_dataframe(self) -> pd.DataFrame:
130130
"""Get raw pandas dataframe.
131131

sec_cik_mapper/MutualFundMapper.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from .BaseMapper import BaseMapper
77
from .retrievers import MutualFundRetriever
8-
from .types import KeyToValueSet, cache
8+
from .types import KeyToValueSet
9+
from .utils import with_cache
910

1011

1112
class MutualFundMapper(BaseMapper):
@@ -24,7 +25,7 @@ def __init__(self) -> None:
2425
super().__init__(MutualFundMapper._retriever)
2526

2627
@property # type: ignore
27-
@cache
28+
@with_cache
2829
def cik_to_series_ids(self) -> KeyToValueSet:
2930
"""Get CIK to series ID mapping.
3031
@@ -40,7 +41,7 @@ def cik_to_series_ids(self) -> KeyToValueSet:
4041
return self._form_kv_set_mapping(cik_col, series_id_col)
4142

4243
@property # type: ignore
43-
@cache
44+
@with_cache
4445
def ticker_to_series_id(self) -> Dict[str, str]:
4546
"""Get ticker to series ID mapping.
4647
@@ -56,7 +57,7 @@ def ticker_to_series_id(self) -> Dict[str, str]:
5657
return self._form_kv_mapping(ticker_col, series_id_col)
5758

5859
@property # type: ignore
59-
@cache
60+
@with_cache
6061
def series_id_to_cik(self) -> Dict[str, str]:
6162
"""Get series ID to CIK mapping.
6263
@@ -72,7 +73,7 @@ def series_id_to_cik(self) -> Dict[str, str]:
7273
return self._form_kv_mapping(series_id_col, cik_col)
7374

7475
@property # type: ignore
75-
@cache
76+
@with_cache
7677
def series_id_to_tickers(self) -> KeyToValueSet:
7778
"""Get series ID to tickers mapping.
7879
@@ -88,7 +89,7 @@ def series_id_to_tickers(self) -> KeyToValueSet:
8889
return self._form_kv_set_mapping(series_id_col, ticker_col)
8990

9091
@property # type: ignore
91-
@cache
92+
@with_cache
9293
def series_id_to_class_ids(self) -> KeyToValueSet:
9394
"""Get series ID to class IDs mapping.
9495
@@ -104,7 +105,7 @@ def series_id_to_class_ids(self) -> KeyToValueSet:
104105
return self._form_kv_set_mapping(series_id_col, class_id_col)
105106

106107
@property # type: ignore
107-
@cache
108+
@with_cache
108109
def ticker_to_class_id(self) -> Dict[str, str]:
109110
"""Get ticker to class ID mapping.
110111
@@ -120,7 +121,7 @@ def ticker_to_class_id(self) -> Dict[str, str]:
120121
return self._form_kv_mapping(ticker_col, class_id_col)
121122

122123
@property # type: ignore
123-
@cache
124+
@with_cache
124125
def cik_to_class_ids(self) -> KeyToValueSet:
125126
"""Get CIK to class IDs mapping.
126127
@@ -136,7 +137,7 @@ def cik_to_class_ids(self) -> KeyToValueSet:
136137
return self._form_kv_set_mapping(cik_col, class_id_col)
137138

138139
@property # type: ignore
139-
@cache
140+
@with_cache
140141
def class_id_to_cik(self) -> Dict[str, str]:
141142
"""Get class ID to CIK mapping.
142143
@@ -152,7 +153,7 @@ def class_id_to_cik(self) -> Dict[str, str]:
152153
return self._form_kv_mapping(class_id_col, cik_col)
153154

154155
@property # type: ignore
155-
@cache
156+
@with_cache
156157
def class_id_to_ticker(self) -> Dict[str, str]:
157158
"""Get class ID to ticker mapping.
158159

sec_cik_mapper/StockMapper.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from .BaseMapper import BaseMapper
77
from .retrievers import StockRetriever
8-
from .types import KeyToValueSet, cache
8+
from .types import KeyToValueSet
9+
from .utils import with_cache
910

1011

1112
class StockMapper(BaseMapper):
@@ -24,7 +25,7 @@ def __init__(self) -> None:
2425
super().__init__(StockMapper._retriever)
2526

2627
@property # type: ignore
27-
@cache
28+
@with_cache
2829
def cik_to_company_name(self) -> Dict[str, str]:
2930
"""Get CIK to company name mapping.
3031
@@ -40,7 +41,7 @@ def cik_to_company_name(self) -> Dict[str, str]:
4041
return self._form_kv_mapping(cik_col, company_name_col)
4142

4243
@property # type: ignore
43-
@cache
44+
@with_cache
4445
def ticker_to_company_name(self) -> Dict[str, str]:
4546
"""Get ticker to company name mapping.
4647
@@ -56,7 +57,7 @@ def ticker_to_company_name(self) -> Dict[str, str]:
5657
return self._form_kv_mapping(ticker_col, company_name_col)
5758

5859
@property # type: ignore
59-
@cache
60+
@with_cache
6061
def ticker_to_exchange(self) -> Dict[str, str]:
6162
"""Get ticker to exchange mapping.
6263
@@ -72,7 +73,7 @@ def ticker_to_exchange(self) -> Dict[str, str]:
7273
return self._form_kv_mapping(ticker_col, exchange_col)
7374

7475
@property # type: ignore
75-
@cache
76+
@with_cache
7677
def exchange_to_tickers(self) -> KeyToValueSet:
7778
"""Get exchange to tickers mapping.
7879
@@ -88,7 +89,7 @@ def exchange_to_tickers(self) -> KeyToValueSet:
8889
return self._form_kv_set_mapping(exchange_col, ticker_col)
8990

9091
@property # type: ignore
91-
@cache
92+
@with_cache
9293
def cik_to_exchange(self) -> Dict[str, str]:
9394
"""Get CIK to exchange mapping.
9495
@@ -104,7 +105,7 @@ def cik_to_exchange(self) -> Dict[str, str]:
104105
return self._form_kv_mapping(cik_col, exchange_col)
105106

106107
@property # type: ignore
107-
@cache
108+
@with_cache
108109
def exchange_to_ciks(self) -> KeyToValueSet:
109110
"""Get exchange to CIKs mapping.
110111

sec_cik_mapper/types.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from functools import lru_cache
2-
from typing import Callable, Dict, List, Set, TypeVar, Union
1+
from typing import Dict, List, Set, TypeVar, Union
32

43
from typing_extensions import Literal, TypedDict
54

@@ -31,7 +30,3 @@ class MutualFundFieldIndices(TypedDict):
3130
KeyToValueSet = Dict[str, Set[str]]
3231

3332
T = TypeVar("T")
34-
35-
36-
def cache(func: Callable[..., T]) -> T:
37-
return lru_cache()(func) # type: ignore

sec_cik_mapper/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from functools import lru_cache
2+
from typing import Callable
3+
4+
from .types import T
5+
6+
7+
def with_cache(func: Callable[..., T]) -> T:
8+
return lru_cache()(func) # type: ignore

0 commit comments

Comments
 (0)