|
1 | | -from abc import abstractmethod |
2 | 1 | from typing import Any, Dict, Mapping, Optional, Tuple, Sequence |
3 | 2 |
|
4 | 3 | import allel # type: ignore |
@@ -180,15 +179,47 @@ def __init__( |
180 | 179 | surveillance_use_only=surveillance_use_only, |
181 | 180 | ) |
182 | 181 |
|
183 | | - @property |
184 | | - @abstractmethod |
185 | | - def _xpehh_gwss_cache_name(self): |
186 | | - raise NotImplementedError("Must override _xpehh_gwss_cache_name") |
| 182 | + def _get_xpehh_gwss_cache_name(self): |
| 183 | + """Safely resolve the xpehh gwss cache name. |
187 | 184 |
|
188 | | - @property |
189 | | - @abstractmethod |
190 | | - def _ihs_gwss_cache_name(self): |
191 | | - raise NotImplementedError("Must override _ihs_gwss_cache_name") |
| 185 | + Supports class attribute, property, or legacy method override. |
| 186 | + Falls back to the default "xpehh_gwss_v1" if resolution fails. |
| 187 | +
|
| 188 | + See also: https://github.com/malariagen/malariagen-data-python/issues/1151 |
| 189 | + """ |
| 190 | + try: |
| 191 | + name = self._xpehh_gwss_cache_name |
| 192 | + # Handle legacy case where _xpehh_gwss_cache_name might be a |
| 193 | + # callable method rather than a property or class attribute. |
| 194 | + if callable(name): |
| 195 | + name = name() |
| 196 | + if isinstance(name, str) and len(name) > 0: |
| 197 | + return name |
| 198 | + except NotImplementedError: |
| 199 | + pass |
| 200 | + # Fallback to default. |
| 201 | + return "xpehh_gwss_v1" |
| 202 | + |
| 203 | + def _get_ihs_gwss_cache_name(self): |
| 204 | + """Safely resolve the ihs gwss cache name. |
| 205 | +
|
| 206 | + Supports class attribute, property, or legacy method override. |
| 207 | + Falls back to the default "ihs_gwss_v1" if resolution fails. |
| 208 | +
|
| 209 | + See also: https://github.com/malariagen/malariagen-data-python/issues/1151 |
| 210 | + """ |
| 211 | + try: |
| 212 | + name = self._ihs_gwss_cache_name |
| 213 | + # Handle legacy case where _ihs_gwss_cache_name might be a |
| 214 | + # callable method rather than a property or class attribute. |
| 215 | + if callable(name): |
| 216 | + name = name() |
| 217 | + if isinstance(name, str) and len(name) > 0: |
| 218 | + return name |
| 219 | + except NotImplementedError: |
| 220 | + pass |
| 221 | + # Fallback to default. |
| 222 | + return "ihs_gwss_v1" |
192 | 223 |
|
193 | 224 | @staticmethod |
194 | 225 | def _make_gene_cnv_label(gene_id, gene_name, cnv_type): |
@@ -725,7 +756,7 @@ def ihs_gwss( |
725 | 756 | ) -> Tuple[np.ndarray, np.ndarray]: |
726 | 757 | # change this name if you ever change the behaviour of this function, to |
727 | 758 | # invalidate any previously cached data |
728 | | - name = self._ihs_gwss_cache_name |
| 759 | + name = self._get_ihs_gwss_cache_name() |
729 | 760 |
|
730 | 761 | params = dict( |
731 | 762 | contig=contig, |
@@ -1249,7 +1280,7 @@ def xpehh_gwss( |
1249 | 1280 | ) -> Tuple[np.ndarray, np.ndarray]: |
1250 | 1281 | # change this name if you ever change the behaviour of this function, to |
1251 | 1282 | # invalidate any previously cached data |
1252 | | - name = self._xpehh_gwss_cache_name |
| 1283 | + name = self._get_xpehh_gwss_cache_name() |
1253 | 1284 |
|
1254 | 1285 | params = dict( |
1255 | 1286 | contig=contig, |
|
0 commit comments