-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle pandas categorical types for categorical columns in _causal_an…
…alysis.py (#602) If the categorical type is set for a treatment column explicitly then there is a failure in `CausalAnalysis` class. ``` ~\AppData\Local\Continuum\miniconda3\envs\nhs-hips\lib\site-packages\econml\solutions\causal_analysis\_causal_analysis.py in individualized_policy(self, Xtest, feature_index, n_rows, treatment_costs, alpha) 1714 all_costs = np.array([0] + [treatment_costs] * (len(treatment_arr) - 1)) 1715 # construct index of current treatment -> 1716 current_ind = (current_treatment.reshape(-1, 1) == 1717 treatment_arr.reshape(1, -1)) @ np.arange(len(treatment_arr)) 1718 current_cost = all_costs[current_ind] ~\AppData\Local\Continuum\miniconda3\envs\nhs-hips\lib\site-packages\pandas\core\ops\common.py in new_method(self, other) 67 other = item_from_zerodim(other) 68 ---> 69 return method(self, other) 70 71 return new_method ~\AppData\Local\Continuum\miniconda3\envs\nhs-hips\lib\site-packages\pandas\core\arrays\categorical.py in func(self, other) 131 if is_list_like(other) and len(other) != len(self) and not hashable: 132 # in hashable case we may have a tuple that is itself a category --> 133 raise ValueError("Lengths must match.") 134 135 if not self.ordered: ``` Solution is to check for the type of the categorical column to see if it is of type `pd.core.arrays.categorical.Categorical` and extract the numpy array using `to_numpy()` method.
- Loading branch information
Showing
2 changed files
with
122 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters