|
12 | 12 | from pandas.core.dtypes.cast import maybe_promote |
13 | 13 | from pandas.core.dtypes.common import ( |
14 | 14 | ensure_platform_int, is_bool_dtype, is_extension_array_dtype, is_list_like, |
15 | | - is_object_dtype, is_sparse, needs_i8_conversion) |
| 15 | + is_object_dtype, needs_i8_conversion) |
16 | 16 | from pandas.core.dtypes.missing import notna |
17 | 17 |
|
18 | 18 | from pandas import compat |
19 | 19 | import pandas.core.algorithms as algos |
20 | | -from pandas.core.arrays import Categorical, SparseArray |
| 20 | +from pandas.core.arrays import SparseArray |
21 | 21 | from pandas.core.arrays.categorical import _factorize_from_iterable |
22 | 22 | from pandas.core.frame import DataFrame |
23 | 23 | from pandas.core.index import Index, MultiIndex |
@@ -82,28 +82,15 @@ class _Unstacker(object): |
82 | 82 | def __init__(self, values, index, level=-1, value_columns=None, |
83 | 83 | fill_value=None, constructor=None): |
84 | 84 |
|
85 | | - self.is_categorical = None |
86 | | - self.is_sparse = is_sparse(values) |
87 | 85 | if values.ndim == 1: |
88 | | - if isinstance(values, Categorical): |
89 | | - self.is_categorical = values |
90 | | - values = np.array(values) |
91 | | - elif self.is_sparse: |
92 | | - # XXX: Makes SparseArray *dense*, but it's supposedly |
93 | | - # a single column at a time, so it's "doable" |
94 | | - values = values.values |
95 | 86 | values = values[:, np.newaxis] |
96 | 87 | self.values = values |
97 | 88 | self.value_columns = value_columns |
98 | 89 | self.fill_value = fill_value |
99 | 90 |
|
100 | 91 | if constructor is None: |
101 | | - if self.is_sparse: |
102 | | - self.constructor = SparseDataFrame |
103 | | - else: |
104 | | - self.constructor = DataFrame |
105 | | - else: |
106 | | - self.constructor = constructor |
| 92 | + constructor = DataFrame |
| 93 | + self.constructor = constructor |
107 | 94 |
|
108 | 95 | if value_columns is None and values.shape[1] != 1: # pragma: no cover |
109 | 96 | raise ValueError('must pass column labels for multi-column data') |
@@ -174,14 +161,6 @@ def get_result(self): |
174 | 161 | columns = self.get_new_columns() |
175 | 162 | index = self.get_new_index() |
176 | 163 |
|
177 | | - # may need to coerce categoricals here |
178 | | - if self.is_categorical is not None: |
179 | | - categories = self.is_categorical.categories |
180 | | - ordered = self.is_categorical.ordered |
181 | | - values = [Categorical(values[:, i], categories=categories, |
182 | | - ordered=ordered) |
183 | | - for i in range(values.shape[-1])] |
184 | | - |
185 | 164 | return self.constructor(values, index=index, columns=columns) |
186 | 165 |
|
187 | 166 | def get_new_values(self): |
|
0 commit comments