|
43 | 43 | from pandas.core.categorical import Categorical
|
44 | 44 | from pandas.core.frame import DataFrame
|
45 | 45 | from pandas.core.generic import NDFrame
|
46 |
| -from pandas.core.index import (Index, MultiIndex, CategoricalIndex, |
47 |
| - _ensure_index) |
| 46 | +from pandas.core.interval import IntervalIndex |
48 | 47 | from pandas.core.internals import BlockManager, make_block
|
49 | 48 | from pandas.core.series import Series
|
50 | 49 | from pandas.core.panel import Panel
|
@@ -3134,12 +3133,20 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3134 | 3133 | if bins is None:
|
3135 | 3134 | lab, lev = algorithms.factorize(val, sort=True)
|
3136 | 3135 | else:
|
3137 |
| - cat, bins = cut(val, bins, retbins=True) |
| 3136 | + raise NotImplementedError('this is broken') |
| 3137 | + lab, bins = cut(val, bins, retbins=True) |
3138 | 3138 | # bins[:-1] for backward compat;
|
3139 | 3139 | # o.w. cat.categories could be better
|
3140 |
| - lab, lev, dropna = cat.codes, bins[:-1], False |
3141 |
| - |
3142 |
| - sorter = np.lexsort((lab, ids)) |
| 3140 | + # cat = Categorical(cat) |
| 3141 | + # lab, lev, dropna = cat.codes, bins[:-1], False |
| 3142 | + |
| 3143 | + if (lab.dtype == object |
| 3144 | + and lib.is_interval_array_fixed_closed(lab[notnull(lab)])): |
| 3145 | + lab_index = Index(lab) |
| 3146 | + assert isinstance(lab, IntervalIndex) |
| 3147 | + sorter = np.lexsort((lab_index.left, lab_index.right, ids)) |
| 3148 | + else: |
| 3149 | + sorter = np.lexsort((lab, ids)) |
3143 | 3150 | ids, lab = ids[sorter], lab[sorter]
|
3144 | 3151 |
|
3145 | 3152 | # group boundaries are where group ids change
|
@@ -3180,12 +3187,13 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
|
3180 | 3187 | acc = rep(d)
|
3181 | 3188 | out /= acc
|
3182 | 3189 |
|
3183 |
| - if sort and bins is None: |
| 3190 | + if sort: # and bins is None: |
3184 | 3191 | cat = ids[inc][mask] if dropna else ids[inc]
|
3185 | 3192 | sorter = np.lexsort((out if ascending else -out, cat))
|
3186 | 3193 | out, labels[-1] = out[sorter], labels[-1][sorter]
|
3187 | 3194 |
|
3188 |
| - if bins is None: |
| 3195 | + # if bins is None: |
| 3196 | + if True: |
3189 | 3197 | mi = MultiIndex(levels=levels, labels=labels, names=names,
|
3190 | 3198 | verify_integrity=False)
|
3191 | 3199 |
|
|
0 commit comments