|
15 | 15 | kernel_optimal_bandwidth, |
16 | 16 | ) |
17 | 17 | from linearmodels.shared.covariance import cluster_union, group_debias_coefficient |
| 18 | +from linearmodels.shared.exceptions import lookup_option, unknown_option_error |
18 | 19 | from linearmodels.shared.typed_getters import ( |
19 | 20 | get_array_like, |
20 | 21 | get_bool, |
@@ -451,7 +452,7 @@ def cov(self) -> linearmodels.typing.data.Float64Array: |
451 | 452 | if self._bandwidth is None: |
452 | 453 | bw = float(np.floor(4 * (xe_nobs / 100) ** (2 / 9))) |
453 | 454 | assert bw is not None |
454 | | - w = KERNEL_LOOKUP[self._kernel](bw, xe_nobs - 1) |
| 455 | + w = lookup_option(KERNEL_LOOKUP, self._kernel, "kernel")(bw, xe_nobs - 1) |
455 | 456 | xeex = cov_kernel(np.asarray(xe_df), w) * (xe_nobs / nobs) |
456 | 457 | xeex *= self._scale |
457 | 458 |
|
@@ -566,7 +567,7 @@ def _single_cov( |
566 | 567 | self, xe: linearmodels.typing.data.Float64Array, bw: float |
567 | 568 | ) -> linearmodels.typing.data.Float64Array: |
568 | 569 | nobs = xe.shape[0] |
569 | | - w = KERNEL_LOOKUP[self._kernel](bw, nobs - 1) |
| 570 | + w = lookup_option(KERNEL_LOOKUP, self._kernel, "kernel")(bw, nobs - 1) |
570 | 571 | return cov_kernel(xe, w) |
571 | 572 |
|
572 | 573 | @cached_property |
@@ -644,14 +645,21 @@ def __init__( |
644 | 645 | self._supported = cov_estimators |
645 | 646 |
|
646 | 647 | def __getitem__(self, item: str) -> CovarianceEstimatorType: |
| 648 | + # The names that the model supports, not all of the names that are known |
| 649 | + supported = [ |
| 650 | + name |
| 651 | + for name, estimator in self.COVARIANCE_ESTIMATORS.items() |
| 652 | + if estimator in self._supported |
| 653 | + ] |
647 | 654 | if item not in self.COVARIANCE_ESTIMATORS: |
648 | | - raise KeyError("Unknown covariance estimator type.") |
| 655 | + raise unknown_option_error("cov_type", item, supported) |
649 | 656 | cov_est = self.COVARIANCE_ESTIMATORS[item] |
650 | 657 | if cov_est not in self._supported: |
651 | | - raise ValueError( |
| 658 | + problem = ( |
652 | 659 | "Requested covariance estimator is not supported " |
653 | 660 | "for the {}.".format(self._estimator) |
654 | 661 | ) |
| 662 | + raise unknown_option_error("cov_type", item, supported, problem=problem) |
655 | 663 | return cov_est |
656 | 664 |
|
657 | 665 |
|
@@ -724,7 +732,7 @@ def cov(self) -> linearmodels.typing.data.Float64Array: |
724 | 732 |
|
725 | 733 | bw = self.bandwidth |
726 | 734 | assert self._kernel is not None |
727 | | - w = KERNEL_LOOKUP[self._kernel](bw, nobs - 1) |
| 735 | + w = lookup_option(KERNEL_LOOKUP, self._kernel, "kernel")(bw, nobs - 1) |
728 | 736 | cov = cov_kernel(e, w) |
729 | 737 | return cov / (nobs - int(bool(self._debiased))) |
730 | 738 |
|
|
0 commit comments